You are on page 1of 9

TECHYMEET - JAVA July 18, 2022

How to set JAVA_HOME environment variable on Windows 10

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

Prerequisites
- Download JDK from Google drive as per TechyMeet Guidelines
https://drive.google.com/drive/folders/1h8b5v8OUOD1FwFMe5LMLT0Ri_6qVCAm2?usp=shari
ng

Note:
1. Download “jdk-8u202-windows-x64.exe” if your windows system Type is 64 bit.
2. Download “jdk-8u202-windows-i586.exe” if your windows system Type is 32 bit.
Run the exe and click “Next” until it shows finish following the installer instructions.

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:

www.techymeet.com
TECHYMEET - JAVA July 18, 2022

Here, the home of JDK is under C:\Program Files\Java\jdk1.8.0_202. 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:

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

www.techymeet.com
TECHYMEET - JAVA July 18, 2022

Then you will see this dialog:

www.techymeet.com
TECHYMEET - JAVA July 18, 2022

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:

www.techymeet.com
TECHYMEET - JAVA July 18, 2022

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:

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:

www.techymeet.com
TECHYMEET - JAVA July 18, 2022

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:

NOTES:

www.techymeet.com
TECHYMEET - JAVA July 18, 2022

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.

5. Code a Java hello world program

Open a simple text editor program such as Notepad and type the following content:

class HelloWorld{
public static void main(String arg[]){
System.out.println("HelloWorld");
}
}

Save the file as HelloWorld.java (note that the extension is .java) under a directory, let’s say,
C:\Java.

Don’t worry if you don’t understand everything in this simple Java code. The following
picture explains it nicely:

Every Java program starts from the main() method. This program simply prints “Hello
world” to screen.

Save the program in D:\MyJavaWorkspace (Create the new folder Name it as


“MyJavaWorkspace”

www.techymeet.com
TECHYMEET - JAVA July 18, 2022

6. Compile your first Java program

Now let’s compile our first program in the HelloWorld.java file using javac tool. Type the
following command to change the current directory to the one where the source file is
stored:

cd D:\MyJavaWorkspace

And type the following command:

javac HelloWorld.java

That invokes the Java compiler to compile code in the HelloWorld.java file into bytecode.
Note that the file name ends with .java extension.

You would see the following output:

If everything is fine (e.g. no error), the Java compiler quits silently, no fuss. After
compiling, it generates the HelloWorld.class file which is bytecode form of the
HelloWorld.java file.

Now try to type dir in the command line, we’ll see the .class file:

So remember a Java program will be compiled into bytecode form (.class file).

www.techymeet.com
TECHYMEET - JAVA July 18, 2022

7. Run your first Java program

It’s now ready to run our first Java program. Type the following command:

java HelloWorld

That invokes the Java Virtual Machine to run the program called HelloWorld (note that
there is no .java or .class extension). You would see the following output:

It just prints out “Hello world!” to the screen and quits. Congratulations! You have
successfully run your first Java program!

6. What we have learnt so far

Throughout this tutorial you have learnt the following things:

 How to install JDK in your laptop/Desktop.


o JDK is the Java SE Development Kit that contains tools and libraries for
Java development.
o JRE is the Java Runtime Environment that enables running Java
programs on your computer.
o JVM is the Java Virtual Machine that actually executes Java programs.
With JVM, programs written in Java can run on multi-platforms (thus Java
is called cross-platform language).
o How to install JDK and configure environment variables.
o javac is the Java compiler. It translates Java source code into bytecode.
o java is the JVM launcher which we use to run our program.
o Every Java program starts from the main() method.
o When compiling, the compiler generates a .class file from a.java file.

www.techymeet.com

You might also like