Indeed, Path.of was later introduced.
Conjecture: it was introduced for the sake of a consistent
Foo.ofstyle.
From the mailing list archive, this method was once called Path.get:
The main changes in are in Path and Paths in java.nio.file.
This patch copies the Paths.get() methods to static methods in Path.get() and modifies the former to call the latter respective methods. The Path specification is slightly cleaned up not to refer to Paths nor itself, e.g., “(see Path).” @implSpec annotations are added to Paths to indicate that the methods simply call their counterparts in Path.
...
This was later changed when Brian Goetz suggested it to be consistent with Foo.of:
Separately, Brian Goetz suggested off-list that it would be more consistent if these factory methods were named "of" so I assume the webrev will be updated to see how that looks.
Now to your last question: "In that case, it would be considered preferable on consistency/aesthetic grounds?"
In the initial mail Brian Burkhalter said that he updated all references to the new method in Path:
All source files in java.base are modified to change Paths.get() to Path.get() and to remove the import for Paths. ...
So I would therefore conclude that Path.of is indeed preferable to Paths.get.
Indeed, if you look at the Javadoc for Paths for Java 13 you will find this note:
Answer from Johannes Kuhn on Stack OverflowAPI Note:
It is recommended to obtain aPathvia thePath.ofmethods instead of via thegetmethods defined in this class as this class may be deprecated in a future release.
java - Paths.get vs Path.of - Stack Overflow
File Paths on Linux (Pi) Vs Windows
How did people set up java support?
debian - How to specify filepath in java? - Stack Overflow
Videos
So I wrote a pretty basic piece of Photo Gallery software in java. Basically it looks through a folder named "photos" that is in the same directory as the jar file, and displays the photos one by one. Now this works perfectly in windows, but when I move it over to my pi and run it in the command line I get a NullPointerException at this line
// open our picture folder
String homeDir = new File(".").getAbsolutePath();
File pictureDirectory = new File(homeDir + File.separator + "photos" + File.separator);
for (File f: pictureDirectory.listFiles()) // go through each fileThe NullPointerException refers to the line with the for loop. This program works perfectly on my windows laptop, and I've looked online and done everything I've found to make it work on Linux too but nothing seems to help. This is my first time ever working on a Linux device so does someone more experienced in this field see my error?
EDIT: Solved Thank you all for your help
I was simply using File pictureDirectory = new File("photos");
In Windows and it works fine but in Linux I had to change it to
File pictureDirectory = new File("Desktop/PhotoGallery/photos"); Because for some reason it sensed my home directory as being /home/pi rather than the location of my jar file. This wasn't the perfect solution for me but it got the job done so it'll work for now.
I just got a new job where we use java, and I was trying to set up neovim, but I can't get it to work properly.
So I simply used lazyvim, it's what I use on my main PC and it always worked perfectly, admittedly with relatively small java projects. Now at work I have a massive java grade java project with a bunch of modules, and I tried to use jdtls (from lazy extras), which didn't quite work, and then I tried making a java.lua file to tweak some things.
No matter what I did, jdtls building would always get stuck at 86%, at which point basic lap functions become basically unusable, for example K or gd.
Is lazyvim the issue? Should I make my own thing from scratch? Is jdtls the issue? What did you guys do? I feel like I tried everything under the sun and I couldn't get it to work.
Are you asking about escape character issues?
If that is the case then use forward slashes instead of backward slashes like
"C:/Users/You/Desktop/test.txt"
instead of
"C:\Users\You\Desktop\test.txt"
If you know the name of the file, of course it's simply
new File("./myFileName")
If you don't know the name, you can use the File object's list() method to get a list of files in the current directory, and then pick the one you want.