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.
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.
After installation, we need to set path and classpath environment variable for Java.
Follow the steps on your Windows system as given below.
C:\Program Files (x86)\Java\jdk1.7.0_67\bin
C:\Program Files (x86)\Java\jre7\lib
Note: These are the respective JDK paths on my system. Find the same on your system.
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.
You can see there are two types of environment variables – User Variable and 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.
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.
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.
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.
Nice tutorial for JAVA setup. I would like to read more about JAVA from this website.
HI Jimmy,
I am glad you like it. We are curating complete Java tutorial from beginner to expert.
Stay tuned!
Do we use the same directory path regardless of the version of Java we are installing?
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.
I’m still having trouble it keeps saying
Jack, it is really difficult to identify the problem with the information you shared. Need more detail.