IO / NOTES</>↗IO30 Dec 2025
In Java 11 and later, Path.of() is the preferred way to create Path instances, effectively replacing Paths.get(). Here is how you can use it: 1. Basic Usage (Replacing Paths.get) The syntax is almost identical. It accepts a string or a sequence of strings to join into a path. package org.kodejava.nio; import java.nio.file.Path; public class PathExample […]
IO / NOTES</>↗IO29 Dec 2025
In Java, java.nio.file.Files.mismatch(Path, Path) is a powerful method introduced in Java 12 that allows you to compare the contents of two files efficiently. It returns the position of the first byte where the two files differ, or -1L if they are identical. How to use Files.mismatch Here is a basic example of how to implement […]
IO / NOTES</>↗IO28 Dec 2025
In Java, Files.readString and Files.writeString (introduced in Java 11) are the most straightforward ways to handle small-to-medium-sized text files. They handle the opening, closing, and encoding for you in a single line of code. Here is how you can use them: 1. Reading a File to a String Files.readString(Path) reads the entire content of a […]
CONCURRENCY / NOTES</>↗Concurrency27 Dec 2025
Debugging concurrency issues (like deadlocks, race conditions, and thread starvation) can feel like chasing ghosts because they are often non-deterministic. Here’s a strategy to tackle them effectively using both design patterns and tools available in your environment. 1. Give Your Threads Meaningful Names The default pool-1-thread-1 names are useless in a thread dump. By using […]
CONCURRENCY / NOTES</>↗Concurrency26 Dec 2025
Creating a custom thread factory in Java is a powerful way to manage how threads are initialized. Instead of using the default factory, you can customize thread names (vital for debugging!), set priority levels, or even create daemon threads. To do this, you need to implement the java.util.concurrent.ThreadFactory interface. 1. Implement the ThreadFactory Interface The […]
CONCURRENCY / NOTES</>↗Concurrency25 Dec 2025
Hello! ExecutorService.invokeAll is a powerful method when you have a collection of tasks and need to wait until every single one of them finishes before moving forward. Here’s a breakdown of how it works and how to use it effectively. What does invokeAll do? Executes a collection of tasks: It takes a Collection of Callable<T> […]