Path.of() factory
Use Path.of() — the modern factory method on the Path interface.
Code Comparison
✕ Java 8
Path path = Paths.get("src", "main",
"java", "App.java");
✓ Java 11+
Path path = Path.of("src", "main",
"java", "App.java");
Why the modern way wins
Consistent API
Follows the .of() factory pattern like List.of(), Set.of().
Discoverable
Found on the Path type itself, not a separate Paths class.
One less class
No need to import the Paths utility class.
Old Approach
Paths.get()
Modern Approach
Path.of()
Since JDK
11
Difficulty
beginner
JDK Support
Path.of() factory
Available
Widely available since JDK 11 (Sept 2018)
How it works
Path.of() is a factory method added directly to the Path interface, replacing the separate Paths utility class. It's more discoverable and consistent with List.of(), Map.of(), etc.