Difference between PATH and JAVA_HOME?

smyers2003 used Ask the Experts™
Can anyone tell me the difference (if any) between setting your PATH variable to point to your jdk, and setting the JAVA_HOME to do the same thing? Does one take precedence over the other?


Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
This is not the same path
The setting the path environment is so your programs/compilers can run smoothly, like where ever you are you can always call java or javac, (not needing to type C:\javasdk\bin\java)

The JAVA_HOME tells where java are, C:\javasdk, so, java programs knows where to find jars and wich java to use (if you have multiple installs)

the path must include: C:\javasdk\bin
and you must have JAVA_HOME=C:\javasdk

where javasdk is your installation

yes both r same..........thats what i think .........as both looks for same thing........
yes both r same..........thats what i think .........as both looks for same thing........
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

They aren't the same!!

one points to "bin" directory and the other to "installation directory" of your java installation

the bin is where all the java components are stored:
such as
javac, java etc.
The other is the home directory of java i.e
where the base java directory is installed
so if you have java installed in the javajdk directory when you type java_home you would get

or if you have it installed in your temp directory on your c drive when u type java-home you would get:

it points to the home directory think of unix when you think of home, where as setting the path is like setting the path for any application so that if you were to type java from a command line it would be able to recognise where java was as you have set the path as for example;
which contains the exe called java

i.e the path _TELLS_ your computer where the files are stored that you use to run java.


Thank you, everyone. So, if I set my PATH to point to C:\jdk1.2.2\bin, and then I set my JAVA_HOME to point to C:\j2sdk1.4.1_02, then my system will use the 1.2.2 JRE but point at the newest jars, components, etc. from the newest JDK (j2sdk1.4.1_02). Is that correct?

yes that is correct it will point to 1.2.2.

No worries!
The best thing for you to do is test this out, make sure however its under a development machine you do it though, check your bin directory and you will see some of the following files:
javap.exe, jar.exe, javac.exe, java.exe appletviewer.exe etc, if you set your path i.e
in autoexec.bat or in windows xp you can do it through panel.
like such:  

set path = c:\jdk1.2.2\
it will use the java.exe file from the JDK 1.2.2 installation i.e this will use the apis from jdk1.2.2 not 1.4, if you do java_home it will give you the directory that you have java installed.


Thank you, Pronane, and I will accept your answer and hopefully you will get the 50 points....

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial