5/21/2006

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.

    33 comments:

    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...

    @lanada333

    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

    Anonymous said...


    I like looking through a post that will make people think. Also, thank you for allowing me to comment!

    UI Development Training In Marathahalli

    Web Designing Training In Bangalore

    Web Designing training institutes Marathahalli bangalore

    Web Designing Course Bangalore



    best Web Designing training center in Marathahalli Bangalore







    Infocampus said...

    A great blog with informative post.

    selenium training in Bangalore
    web development training in Bangalore
    selenium training in Marathahalli
    selenium training institute in Bangalore
    best web development training in Bangalore
    selenium training in marathahalli

    Infocampus said...

    selenium training in marathahalli

    Pugazhendhi Dhamodaran said...

    This is so interesting! Android training in Bangalore i don't believe I've really read through anything like that before. therefore fantastic to get another person Android training in Bangalore with a few unique thoughts on this issue. Seriously.. many thanks for starting this up. This website is something that's required on the web, somebody with a small amount of originality!

    Service Center Casio said...

    Indonesia
    Easy
    Learning
    Indonesian
    Jual Beli HP
    bimbelbateraiLampung
    Service HPlampungservice.com

    Digital Marketing Institute in Delhi said...

    BECOME A DIGITAL MARKETING
    EXPERT WITH US. Call Us For More Info. +91-9717 419 413, 8057555775
    COIM offers professional Digital Marketing Course Training in Delhi to help you for jobs and your business on the path to success.
    Digital Marketing Institute in Greater Noida
    Digital Marketing Course in Laxmi Nagar
    Digital Marketing Institute in Delhi
    Digital Marketing training in Preet Vihar
    Online Digital Marketing Course in India
    Digital Marketing Institute in Delhi
    Digital Marketing Institute in Delhi
    Digital Marketing Institute in Alpha

    ritu said...

    Thanks for sharing such helpful information with all of us I appreciate your effort of writing a value able piece of content.
    http://www.rankingsstar.com

    Digital Marketing Service said...

    Hi,

    Thanks for sharing information. I have read all details i really tell you good content and also good website.

    Best honeymoon place in himachal
    Best places to visit in delhi
    best honeymoon place in kerala
    best tourist place in goa
    best tourist places in jharkhand
    places to visit in uttar pradesh
    honeymoon destinations in india
    five star hotels in delhi
    most romantic honeymoon destinations in india


    Thanks

    Top 10 Iconic Places to Visit in Delhi said...

    Thanks for given information about above Article all the details
    are very useful.

    Institute Coim said...

    thanks for information.
    Home Salon

    Vaishviktrends.com said...

    If you are looking for Best Gyms in Ghaziabad then click on the given link.

    Digital Marketing Service said...

    Best Adventure place in Himachal

    Best honeymoon place in himachal
    Best tourist place in delhi
    best honeymoon place in kerala
    best tourist place in goa
    best tourist places in jharkhand
    places to visit in uttar pradesh
    honeymoon destinations in india
    most romantic honeymoon destinations in india
    five star hotels in delhi
    five star hotels in delhi list
    list of all 5 star hotels in delhi
    5 star hotels in delhi near airport
    hotel in delhi
    hotels in delhi near railway station

    Top 10 Iconic Places to Visit in Delhi said...

    Thanks for given information about above Article all the details
    are very useful.

    Digital Marketing Service said...



    Hi,

    Thanks for sharing very useful information and i request to you please keep sharing ahead.

    Thanks

    Top 10 Iconic Places to Visit in Delhi said...

    Thanks for given information about above Article all the details
    are very useful.

    deepika said...

    Very Informative information .
    spring mvc interview questions

    BluePrint Global said...

    Booth Contractor Cologne

    Top 10 Iconic Places to Visit in Delhi said...

    Thanks for given information about above Article all the details
    are very useful.

    unknow said...


    I really enjoyed your blog Thanks for sharing such an informative post.
    https://myseokhazana.com/
    https://seosagar.in/
    Indian Bookmarking list
    Indian Bookmarking list
    India Classified Submission List
    Indian Classified List
    Indian Bookmarking list
    Indian Bookmarking list
    India Classified Submission List
    Indian Classified List

    unknow said...

    I really enjoyed your blog Thanks for sharing such an informative post.
    https://www.friendshipclubonline.com
    Friendship Club In India
    Friendship Club In Mumbai
    Friendship Club In Delhi
    Friendship Club
    Friendship Chandigarh

    Unknown said...

    Nice Post thanks for the information, good information & very helpful for others,Thanks for Fantasctic blog and its to much informatic which i never think ..Keep writing and grwoing your self

    duplicate rc in delhi online
    duplicate rc in ghaziabad
    duplicate rc in online
    duplicate rc in greater noida
    duplicate rc in mumbai
    duplicate rc in bangalore
    duplicate rc in faridabad
    duplicate rc in gurgaon
    duplicate rc in noida
    death certificate online