Step by Step Java Environment Variables Setup [JDK Installation Guide]
Java is widely used in many applications and also provides computing power for numerous websites. In a previous article, we have seen the introduction and features of Java. In this post, I share a complete JDK installation guide and Java environment variables Setup.
To run the Java application, there is a Java Development Kit (JDK) to install. And there are two environment variables to set. One is a path and the other is a classpath variable.
Install JDK on Windows
First of all, download the latest JDK from its official website of Oracle.
Install downloaded JDK software on your system.
Note: In the case of Windows, by default, Java will be installed at directory path C:\Program Files\Java
.
After installation opens this directory path. You can find, there are two folders (jdk1.x… and jre ).
Here is a complete JDK file hierarchy inside the Java folder.
Java Environment Variables Setup Steps
After installation, we need to set path and classpath environment variable for Java.
Follow the steps on your Windows system as given below.
- Right-click on My Computer.
- Select Advanced System Setting.
- Click on Environment Variables (at the bottom right corner).
- There will be two environment variables, one is the User variable and another is a System variable.
- If path and classpath variables are already present in System Variable, click on it to edit. Otherwise, set a new variable.
- Set the path variable by adding the following directory path.
C:\Program Files (x86)\Java\jdk1.7.0_67\bin
- Set the classpath variable by adding the 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 Java JDK 7.
Now you have done with Java JDK setup. You are ready to 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 a 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 a 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 the System variable.
By setting user variables, the only particular user is able to run a Java program. Other users on the system can not access the Java installation file to run the Java program.
If you want all users should be able to run Java application, set an environment variable in the System Variable. After this, all the user can run a 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 know why there is a need for Java environment variables setup.
So let’s see…
If you have not set a 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 providing a complete path every time to run the Java program really convenient for you?
Not at all!
If you set the path variable, you can run a Java program from any file directory without specifying the complete Java tool path.
>>javac HelloWorld.java
Yep! It is simple, convenient and easy to run any Java program by setting environment variables.
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.
C:\>echo %path%
C:\>echo %classpath%
This is the completed guide for JDK installation and setting Java variables. I tried to cover some frequently asked questions about the Java environment variables setup. If you have any more questions, feel free to write in the comment section below.
Comments
Jimmy
Nice tutorial for JAVA setup. I would like to read more about JAVA from this website.
Aniruddha Chaudhari
HI Jimmy,
I am glad you like it. We are curating complete Java tutorial from beginner to expert.
Stay tuned!
Rajish
Do we use the same directory path regardless of the version of Java we are installing?
Aniruddha Chaudhari
Mostly yes. The directory path can change based on the Operating System. It is always good to check if the path is valid or not before setting it as a value for environment variable.
Jack
I’m still having trouble it keeps saying
Aniruddha Chaudhari
Jack, it is really difficult to identify the problem with the information you shared. Need more detail.