Step by Step Java Environment Variables Setup [JDK Installation Guide]
Java is widely used in many applications and also provides computing power for the numerous websites. In a previous article, we have seen introduction and features of Java. In this post, I share complete JDK installation guide and Java environment variables Setup.
To run Java application, there is Java development Kit (JDK) to install. And there are two environment variables to set up. One is a path and other is a classpath variable.
Install JDK on Windows:
Download latest JDK from its official website of Oracle.
Install downloaded JDK software on your system.
Note: It will install at “C:\Program Files\Java” by default.
You can find, there are two folders in Java (jdk1.x… and jre ).
In the following image, you can find JDK Java folder hierarchy.
Java Environment Variables Setup Steps:
Now we set path and classpath environment variable for Java.
- Right-click on My Computer.
- Select Advance System Setting.
- Click on Environment Variables… at bottom right corner.
- There will be two environment variables, one is User variable and other is a System variable. Select
- If path and classpath variables are already present in System Variable, click on it to edit. Otherwise, set new variable.
- Set path variable by adding following directory path.
C:\Program Files (x86)\Java\jdk1.7.0_67\bin
- Set classpath variable by adding following classpath directory path.
C:\Program Files (x86)\Java\jre7\lib
Note: These are the respective JDK paths on my system. Find the same on your system.
- Click on OK.
All the screenshots have taken on Windows OS for installation of JDK 7.
Now you have done with Java JDK setup. Run your first Hello World java program.
All the Best!
Let’s discuss some frequently asked questions… The questions, everyone should know especially if you are a beginner.
How to set up the environment variable for Particular User?
You can see there are two types of environment variables – User Variable and System Variable.
- If you want to set java path and classpath for the particular user on Window system, change path and classpath in User variables.
- If you want to set Java for all the users on the system, modify path and classpath in System variables.
By setting user variable, the only particular user is able to run Java program. Other users on the system can not access Java installation file to run Java program.
If you want all user accessing Java installation files, set an environment variable in System variables. All the user can run Java program.
Why do you need to Set Path and Classpath Environment variable in Java?
Many programmers, knows how to set path in Java. But very few knows why there is a need for Java environment variables setup.
So let’s see…
If you have not set path variable, you need to provide a full path of java installed file to run every Java program on your system.
>>C:\Program Files (x86)\Java\jdk1.7.0_67\bin\javac HelloWorld.java
Is it really convenient to use?
There may be a possibility to mismatch path and it is also time-consuming.
If you set the path variable, you can run Java program from any file directory without specifying complete Java tool path.
It is simple, convenient and easy to run Java program by setting environment variables. Right?
What is the difference between Path and Classpath Variables:
I have already covered this question in my previous article in detail. You can refer it to find the difference between Path and Classpath variable.
How to check Java Path And Classpath Variables?
You can rectify the path and classpath variable on the command prompt. Run the following commands. It will display all the directives in both path and classpath variables.
Run the following commands. It will display all the directives in both path and classpath variables.
This is completed guide for JDK installation and setting Java variables. I tried to cover some frequently asked questions about Java environment variables setup. If you have any more question, feel free to write in comment section below.