In this article, you will understand the details about JAVA_HOME environment variable and how to set it on Windows 10. 

What is JAVA_HOME?

By convention, JAVA_HOME is the name of an environment variable on the operating system that points to the installation directory of JDK (Java Development Kit) or JRE (Java Runtime Environment) – thus the name Java Home. For example:

JAVA_HOME = c:\Program Files\Java\jdk1.8.0_201
 

Why is JAVA_HOME needed?

To develop Java applications, you need to update the PATH environment variable of the operating system so development tools like Eclipse, NetBeans, Tomcat… can be executed because these programs need JDK/JRE to function. So the PATH environment variable should include JAVA_HOME:

PATH = Other Paths + JAVA_HOME
Other paths are set by various programs installed in the operating system. If the PATH environment variable doesn’t contain a path to JRE/JDK, a Java-based program might not be able to run. For example, typing java in the command prompt showing this error:

'java' is not recognized as an internal or external command, operable program or batch file.
error java command

Or Eclipse will fail to launch:



Eclipse launch error no Java home found

 

How to set JAVA_HOME on Windows 10

Here are the visual steps to properly set value for the JAVA_HOME and update the PATH environment variables in order to setup Java development environment on your computer:

1. Firstly, you need to identify the Java home directory, which is typically under C:\Program Files\Java directory. Open My Computer and navigate to this directory, you will see:

Java home directory

Here, the home of JDK is under C:\Program Files\Java\jdk1.80_201. The version number may vary, depending on the JDK you installed.

 

2. Open the System Environment Variables dialog by typing environment in the search area on Start menu. Click the suggested item Edit the system environment variables:

start menu open system environment variable dialog

The System Properties dialog appears, click the button Environment Variables.

System properties dialog

Then you will see this dialog:

Environment Variables dialog

 

3.Create the JAVA_HOME environment variable by clicking the New button at the bottom. In the New System Variable form, enter the name and value as follows:

New JAVA HOME system variable

 

Click OK, and you will see the JAVA_HOME variable is added to the list.

 

4.Update the PATH system variable. In the Environment Variables dialog, select the Path variable and click Edit:

Edit Path variable

Then in the Edit environment variable dialog, double click on the empty row just below the last text line, and enter %JAVA_HOME%\bin as follows:

Edit Path variable for Java home

The percent signs tell Windows that it refers to a variable – JAVA_HOME, and the \bin specifies the location of java.exe and javac.exe programs which are used to run and compile Java programs, as well as other tools in the JDK.

Click OK button to close all the dialogs, and you’re all set. Now you can open Eclipse or NetBeans to verify. Or open a command prompt and type in javac –version, you should see:

verify java home

NOTES:

You can add the path to the bin directory of Java home directly into the PATH variable. But it’s strongly recommend to follow the above steps to setup a JAVA_HOME variable because many Java programs depend on it.

When you installed a JDK, you might not need to update the system variable because the installer already did it for you.

 

Learn more:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment

   


Comments 

#25Durjay Dev nath2024-08-21 03:50
i need this setup. kindly help to setup the function
Quote
#24Guy2023-07-23 08:09
Can you show us how to run a program on java please?
Quote
#23Guy2023-07-23 07:38
This, unlike other articles, helped me alot
Quote
#22chet2023-07-14 12:13
Thank you for this helpful article
Quote
#21Arnal2023-02-13 07:42
Thank you for this helpful article !
With your help I managed to get rid of an annoying message poping every minute.
Quote