Java Env Setup
Java Env Setup
Java Env Setup
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.
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
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.
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.
www.techymeet.com
TECHYMEET - JAVA July 18, 2022
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
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.
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
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!
www.techymeet.com