Setting the JAVA_HOME and PATH Environment Variables on Windows 7

Java Settings on Windows

After we install Java Development Kit (JDK) on Windows, we need to configure the JAVA_HOME and Path environment variables so that the operating system can find the JDK command-line tools.

In this guide, we will show you how to setup JAVA_HOME and Path environment variables on Microsoft Windows 7 operating system.

What We Used

1. Set the JAVA_HOME variable

Click the Start menu, right click Computer and then select Properties.

Computer Properties Menu

Click the Advanced System Settings link to open the System Properties dialog box.

System Properties Dialog Box

Click the Environment Variables button to open the Environment Variables dialog box.

Environment Variables Dialog Box

Under System Variables, click the New button to add JAVA_HOME variable and enter the JDK installation path C:\Program Files (x86)\Java\jdk1.8.0_60 as variable value. If the path contains spaces, we can use the shortened path name, for example C:\PROGRA~2\Java\jdk1.8.0_60

Add JAVA_HOME Variable

Tip: For 64-bit Windows users, these are the shortened path name for Program Files directory:

  • PROGRA~1 = Program Files
  • PROGRA~2 = Program Files (x86)

2. Set the PATH variable

Under System Variables, find the Path variable and click the Edit button. Then, add the JDK bin folder %JAVA_HOME%\bin to the beginning of the Path value.

Edit Path Variable

Note: Remember to put a semicolon character ; as delimiter to separate the Maven bin path with other paths.

3. Verify

In final step, close and re-open the command prompt window to reload the latest changes of the environment variables. Execute the following commands in the command prompt window:

echo %JAVA_HOME%
java -version
javac -version

The output will show your installed version of JDK like below:

C:\Users\chankok>echo %JAVA_HOME%
C:\PROGRA~2\Java\jdk1.8.0_60

C:\Users\chankok>java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode)

C:\Users\chankok>javac -version
javac 1.8.0_60

Summary

Congratulations! You have successfully configured the JAVA_HOME and Path environment variables on Windows 7. Now you can start develop your Java application.

Other Resources