When a new version of JRE is installed, this path C:\Program Files (x86)\Common Files\Oracle\Java appears to be updated with executables corresponding to the new JRE version. The problem is this would be JRE and not JDK. So, programs that depend on JDK (IDE for example) will fail to launch.
Here is how I get it to work consistently
- I always have an environment variable in User Variables (System Environment Variables by going to Control Panel -> System -> Advanced System Settings -> Environment Variables -> User Variables) --
JAVA_HOMEpointing to the JDK Home. And add%JAVA_HOME%\binto thePATHenvironment variable. - Interestingly, I remove the entry
C:\Program Files (x86)\Common Files\Oracle\Java\javapathfrom thePathenvironment variable in System Environment Variables (Control Panel -> System -> Advanced System Settings -> Environment Variables -> System Variables).
This works as of Aug 2020 for Windows 10 (1903), Java 8u251. :)
Answer from Rakesh N on Stack OverflowHow to best set the path to java in windows - Stack Overflow
debian - How to specify filepath in java? - Stack Overflow
Java: Path vs File - Stack Overflow
rhel - How to find path where jdk installed? - Unix & Linux Stack Exchange
Videos
When a new version of JRE is installed, this path C:\Program Files (x86)\Common Files\Oracle\Java appears to be updated with executables corresponding to the new JRE version. The problem is this would be JRE and not JDK. So, programs that depend on JDK (IDE for example) will fail to launch.
Here is how I get it to work consistently
- I always have an environment variable in User Variables (System Environment Variables by going to Control Panel -> System -> Advanced System Settings -> Environment Variables -> User Variables) --
JAVA_HOMEpointing to the JDK Home. And add%JAVA_HOME%\binto thePATHenvironment variable. - Interestingly, I remove the entry
C:\Program Files (x86)\Common Files\Oracle\Java\javapathfrom thePathenvironment variable in System Environment Variables (Control Panel -> System -> Advanced System Settings -> Environment Variables -> System Variables).
This works as of Aug 2020 for Windows 10 (1903), Java 8u251. :)
On my machine, the files in C:\ProgramData\Oracle\Java\javapath used to symlink to files elsewhere. But noticed this has changed in or before 8u112. Worth noting that on my current release (8u171) both javapath folders symlink to "target" folders in the same directory.
If I undo the things in c:\programdata I notice that my Eclipse environment stops working well.
But I don't have much more insight on the history or why behind all of this though.
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.
Simply do (in terminal):
update-alternatives --list java
And you'll get an output like this:
$ update-alternatives --list java
/usr/bin/gij-5
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
The last line is the place your java is in.
You need to dig into symbolic links. Below is steps to get Java directory
Step 1:
$ whereis java
java: /usr/bin/java /etc/java /usr/share/java
That tells the command java resides in /usr/bin/java.
Step 2:
$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 2009-01-15 18:34 /usr/bin/java -> /etc/alternatives/java
So, now we know that /usr/bin/java is actually a symbolic link to /etc/alternatives/java.
Dig deeper using the same method above:
Step 3:
$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 31 2009-01-15 18:34 /etc/alternatives/java -> /usr/local/jre1.6.0_07/bin/java
So, thats the actual location of java: /usr/local/jre.....
You could still dig deeper to find other symbolic links.
Reference : where is java's home dir?
Long story short:
java.io.File will most likely never be deprecated / unsupported. That said, java.nio.file.Path is part of the more modern java.nio.file lib, and does everything java.io.File can, but generally in a better way, and more.
For new projects, use Path.
And if you ever need a File object for legacy, just call Path#toFile()
Migrating from File to Path
This Oracle page highlights differences, and maps java.io.File functionality to java.nio.file lib (including Path) functionality
Article by Janice J. Heiss and Sharon Zakhour, May 2009, discussing NIO.2 File System in JDK 7
can we consider it deprecated?
No, you can't consider it deprecated unless and until it is so marked in the File Javadoc.
Try either of the two:
$ which java
$ whereis java
For your first java program read this tutorial:
"Hello World!" for Solaris OS and Linux
On RHEL7, you can use locate:
locate openjdk
or find:
find / -iname "*openjdk-*"
and it led me to the /usr/lib/jvm/ directory which contained the directories:
java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/
jre/
jre-1.8.0/
jre-1.8.0-openjdk/
jre-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/
jre-openjdk/
Each of these contain a bin/java
To find the full path of the symbolic link use:
readlink -f $(which java)
*Credit: Answer on Stack Overflow
what does adding java to path does on windows? I started a local java short course sometime ago but I had to differ it. I started watching some online tutorials but none of them added java "to path" (system properties ->Environment Variables -> click on path -> click edit -> click new paste (C:\Program Files\Java\jdk-17\bin) which I did in the local course I joined.