How to Set the JAVA_HOME Variable in Windows 10

Advertisements
WordPress.com

Setting the Java_Home Variable In Windows 10: This can be followed in Windows 8 and Windows 7 too.

This article will guide you How to set java_home variable classpath in Windows 10.

JAVA_HOME is an environment variable (in Unix terminologies), or a PATH variable (in Windows terminology). A lot of well behaving Java applications (which need the JDK/JRE) to run, looks up the JAVA_HOME variable for the location where the Java compiler/interpreter may be found.

After you’ve installed Java in Windows, you must set the ” JAVA_HOME”  environment variable to point to the Java installation directory.

What are Environment Variables?

Environment variables are global system variables accessible by all the processes running under the Operating System (OS). Environment variables are useful to store system-wide values such as the directories to search for the executable programs (PATH) and the OS version. Examples of environment variables in Windows OS are:

  • COMPUTENAMEUSERNAME: stores the computer and current username.
  • OS: the operating system.
  • SystemRoot: the system root directory.
  • PATH: stores a list of directories for searching executable programs.

In setting up JDK and Java applications, you will encounter these environment variables: PATHCLASSPATHJAVA_HOME and JRE_HOME.

In short:

  • PATH: maintains a list of directories. The OS searches the PATH entries for executable programs, such as Java Compiler (javac) and Java Runtime (java).
  • CLASSPATH: maintain a list of directories (containing many Java class files) and JAR file (a single-file archive of Java classes). The Java Compiler and Java Runtime searches the CLASSPATH entries for Java classes referenced in your program.
  • JAVA_HOME and JRE_HOME: maintain the locations of JDK and JRE installed directory, respectively.

This information is only relevant if you’ve installed Java JDK or Java JRE in Windows.

There are two scenarios:

  1. If you installed the Java Development Kit (JDK) you’ll be setting the JAVA_HOME environment variable.
  2. If you installed the Java Runtime Environment (JRE) you will follow the same steps but set the JRE_HOME environment variable instead.

Procedure to Set the JAVA_HOME Variable in Window 10.

We are assuming that you have a 64-bit system and a 64bit Windows Operating System. For example; Windows 10 64bit.

To set the JAVA_HOME variable:

  1. Find out where Java is installed. If you didn’t change the path during installation, it would be something like this: C:\Program Files\Java\jdk-9.0.1
  2. In the desktop right-click My Computer/This PC/ or open Explorer and select Properties > Advanced.
    You can also goto Control Panel > System > Advanced System Settings.
  3. Then Click the Environment Variables button.
  4. There will be System Variables; now under System Variables click New.
  5. In the Variable Name field, enter:
    • JAVA_HOME if you installed the JDK (Java Development Kit)
      or
    • JRE_HOME if you installed the JRE (Java Runtime Environment)
  6. In the Variable Value field, enter your JDK or JRE installation path.If the path contains spaces, use the shortened pathname,
    for example:C:\Program Files\Java\jdk-9.0.1)

Note for Windows users on 32-bit & 64-bit systems

Progra~1 = ‘Program Files’ //This is for 64bit users
Progra~2 = ‘Program Files(x86)’ // This is for 32bit users

  1. Click OK and Apply Changes as prompted.

Finally, you’re done. To observe any effect, you’ll need to close and re-open any command windows that were open before you made these changes.

As there’s no way to reload environment variables from an active command prompt. If the changes don’t take effect even after reopening the command window, restart Windows.


Thanks for reading this tutorial. If you have any questions, you can ask me in the comments section below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.