JAVA_HOME vs java.home

What's the difference between JAVA_HOME and java.home? JAVA_HOME is the JDK install directory, e.g., C:\jdk5. It's meant to be set as an environment variable and referenced in Windows batch files or Unix scripts. I always have it in my Windows Control Panel and .tcsh files,along with other common environment variables. Some Java applications use the name jdk.home for this purpose, which I think is a better name. But JAVA_HOME has been used since the beginning and is now a convention.

java.home is the JRE install directory, e.g., C:\jdk5\jre, or C:\Program Files\Java\jre1.5.0_06. Unlike JAVA_HOME, I never seen java.home as an environment variable. java.home is a build-in Java system property, whose value is the JRE install directory. Since all Java system properties are also exposed as Ant build properties, you can also use ${java.home} in build files.

Would jre.home be a better name? Maybe, but I don't think Sun will change it.

Therefore, java.home is always there inside JVM, whereas JAVA_HOME exists mainly in your shell environment and you may pass it to JVM as a system property. Why do we still need JAVA_HOME? Well, there are good reasons:

  • You can add $JAVA_HOME/bin to the beginning of your PATH, to make sure you always invoke the right java program. On Windows, java.exe is duplicated in several places, for instance %JAVA_HOME%\bin\java.exe, $JAVA_HOME\jre\bin\java.exe, and %SystemRoot%\system32\java.exe. Without have $JAVA_HOME/bin at the beginning of the PATH, a java command will always resolve to %SystemRoot%\system32\java.exe, which may not be what you want. The same problem can also exist in Linux/Solaris.

  • Some Java application runtime needs to use tools/libraries only available in JDK. For example, web containers need tools.jar in JDK to compile JSP pages, and ejb containers also need to invoke javac/rmic tools in JDK. So the build-in system property java.home is not sufficient.


    lanada333 said...

    Hi every one
    That's information is clear and interesting but were I can put the JAVA_HOME path in a (WINDOWS7 or VISTA) to reconice the NetBeans are installed in my system
    Tankyou for all and perdon by my English.

    Anonymous said...


    Vista: Start -> right click on computer -> Properties -> Advanced System Settings -> Environment Variables -> New.. (in 'User Variables') and you add your new variable.

    VirtualVAT said...

    JAVA_HOME is system environment variable and java.home is JVM property. Either one or another can be used to specify java home directory for the virtual machine.

    jane rechod said...

    I'm new to this - but I need to get my head round it for a work project. So, is the java.home property universal throughout the JVM or just local to where it's declared?

    javahowto said...

    You can say it's universal across teh JVM. That is, after starting the JVM, java.home system property is there until JVM shutdown.

    Sandeep Kumar said...

    Nice tutorial. You can also refer this link to to set environment variables PATH, CLASSPATH and JAVA_HOME for compiling and running of Java applications. http://www.a2ztechguide.com/2011/10/setting-environment-variables-javahome.html

    Odisha Real Estate said...

    This is very informative post. Thank you so much for sharing..
    Real Estate in India

    Anna said...

    Great and Useful Article.

    Online Java Course

    Java Online Training

    Java Course Online

    J2EE training

    online J2EE training

    Best Recommended books for Spring framework

    Java Interview Questions

    Java Training Institutes in Chennai

    Java Training in Chennai

    J2EE Training in Chennai

    java j2ee training institutes in chennai

    lisa steve said...

    I’m eager to find the valuable information and for me this is the right place to get the good stuff. http://handytoolshome.com/

    Java Training in Bangalore said...

    This is the right site for everyone who would like to find out about this topic.
    Java/J2ee Classes Bangalore
    Java Training Center Bangalore
    Java Training in Bangalore
    Best Core Java Training in Bangalore
    java Courses in Bangalore
    Best Java Training Institute Bangalore Marathahalli
    Core and Advanced Java Institute in Marathahalli
    Java Training Institute in Bangalore Marathahalli
    Advanced java Training in Bangalore
    Advanced java Training in Bangalore

    suresh babu s said...

    Nice info!
    suresh babu

    suresh babu s said...

    This is the right site for everyone who would like to find out about this topic. You realize so much its almost tough to argue with you (not that I actually would want to…HaHa). You definitely put a fresh spin on a topic which has been discussed for ages. Wonderful stuff, just great!
    Angular 2 Training in bangalore , Angular 4 Training in bangalore , Angular 5 Training in bangalore , Angular 6 Training in bangalore , Angular 7 Training in bangalore , Angular 2 Institute in bangalore , Angular 4 Courses in bangalore , Angularjs Classes , Angularjs Training in Bangalore , Angularjs Training Institute Bangalore , AngularJS Classes in Bangalore , Python Training in Bangalore