Reputation: 3573
I installed the Oracle JDK to /usr/jdk/jdk1.8.0_25 and set that directory to JAVA_HOME. JAVA_HOME/bin contains the java executable and JAVA_HOME/jre/bin contains another java executable. The guide I followed said to add JAVA_HOME/bin and JAVA_HOME/jre/bin to the PATH but which is the correct executable to use and which will be used if I call java from the command line?
Upvotes: 4
Views: 5099
Reputation: 16041
If you are really curious, you can write this to the command line:
where java
This will give the exact location of the executable. On my PC this gives me
C:\ProgramData\Oracle\Java\javapath\java.exe
which is a soft link for the system default runtime java.exe
(in my case it is C:\Program files\Java\jre 1.8.0_25\bin\java.exe
)
Upvotes: 0
Reputation: 28706
Here is a simplified overview of the differences between JDK and JRE
JRE means JavaRuntimeEnvironment : it contains only binaries for running java program
JDK means JavaDevelopmentKit : it contains binaries for running java program + binaries to compile java source code (and produce a java program).
A JDK always contains a JRE inside (under directory <JDK_HOME>/jre
)
The major difference between JRE and JDK is the javac program. (javac means java compiler)
(you will also find some other programs under the <JDK_HOME>/bin
that aren't present under <JDK_HOME>/jre/bin
: all of them may be useful to do java development - but in most case - useless to run a java program.
All programs that are in both locations (i.e. <JDK_HOME>/bin
and <JDK_HOME>/jre/bin
) are the same, so it is not very important to make a distinction.
To answer precisely to your question : the java instance that will run when you execute a command line starting with java is the first instance of java found in your PATH system variable... just like any other program.
Upvotes: 6
Reputation: 3913
Whatever is earlier in the path for java - JAVA_HOME/bin or JAVA_HOME/jre/bin.
If you take a look at the folder structure where jdk / jre is installed you would see that in the jdk/bin folder there are quite a collection of binaries such as java, javac, javap etc. The JRE would include java but not javac, javap etc. I am assuming this is linux and you downloaded the compressed archive and extracted that.
Upvotes: 0