Setting up a JAVA_HOME and Path variables is the second thing you’ll need to do after installing a JDK (Java Development Kit). Although this is not required by Java it self, it is commonly use by other application. For instance then Tomcat application server and other application server will need it. Or you might need it if you want to compile or running your Java classes from the command prompt so that help you organize the default JDK and the execution path.
So here are some steps that you’ll need to do to configure the JAVA_HOME and Path variable on a Windows operating system.
Step 1. Finding the location of your JDK installation directory. If you already know where you have installed the JDK continue to the Step 2.
- The JDK usually installed in the C:Program FilesJava directory by default.
- Under this directory you can find one or more version of installed JDK, for examples I have jdk1.6.0_39 and jdk1.7.0_13. Just choose the default that one you’re going to use.
Step 2. Setting JAVA_HOME variable
After you know the location of your JDK installation, you can copy the directory location from the Windows Explorer address bar.
- Open Windows Explorer
- Right Click the Computer and select the Properties menu.
- Click Advanced system settings and the System Properties windows will be shown.
- Select the Advance tab.
- Click the Environment Variables button.
- A new Environment Variables window will be shown.
- Under the System Variables, click the New button to create a new environment variable.
- Enter the variable name as JAVA_HOME, all letters are in uppercase.
- In the variable value enter the JDK installation path you’ve copy above.
- Click OK.
Step 3. Setting the Path variable
After you’ve set the JAVA_HOME variable, now you can update the Path variable.
- In the Environment Variables window, under the System Variables section find a variable named Path.
- If you don’t have the Path variable you need to add one using the New button.
- If you already have the Path variable you’ll need to update it’s value, click Edit button to update.
- Add %JAVA_HOME%bin; to the beginning of the Path variable value.
- Press OK to when you are done.
- Press another OK to close the Environment Variables window.
Step 4. Check to see if the settings work
- Open your Windows Command Prompt.
- Type java -version in the command line.
- If everything was set correctly you’ll see the running version of your installed Java JDK.
As an example on my Windows Command Prompt I have something like:
java version "1.7.0_13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) Client VM (build 23.7-b01, mixed mode)
If you don’t see the correct output, for instance you get an error like “‘java’ is not recognized as an internal or external command,
operable program or batch file”, please retry the steps described above. Enjoy your new adventure with Java programming. Happy coding!