Let us see how to set up the environment variables in a Windows Operating System, in order to execute your first Java program.
Open the folder where the Java Development Kit(JDK) is installed in your system.
Next, open the bin folder in the JDK folder and copy the path to this folder.
In our case, we have installed JDK in its default directory -
"C:\Program Files\Java\jdk1.8.0_144"
Hence, the path of the bin folder in JDK in our system is -
C:\Program Files\Java\jdk1.8.0_144\bin
Next, in the search box of the Windows Operating System(Windows 7 to Windows 10), type in a Windows command sysdm.cpl and press the Enter button, which opens the System Properties window.
Figure 1
Once the window of System properties opens up, we need to click on its tab that says, Advanced.
Figure 2
In the Advanced tab window, we need to click on the button that says, Environment Variables, to set the environment variables for executing the Java programs.
Figure 3
Advertisement
In the next window of Environment Variables, we first need to click on Path variable in the section of System variables
and then click on the Edit button, to edit the value of this Path System variable.
Figure 4
Clicking the Edit button to edit the value of the Path System variable, opens
a new dialog window of Edit System Variable. This window has two options - Variable name and Variable value.
Against the box of Variable value, we need to paste the path to the bin folder of JDK(please, don't forget to add a semicolon at the end of this path.)
Next, click the OK button to save the new value of the Path System variable.
Figure 6
Next, click the OK button on the previous window of Environment Variables, to save and apply the changes.
Figure 5
Next, in the search box of the Windows Operating System(Windows 7 to Windows 10), type in the Windows command cmd and press
Enter button to open the Command Prompt window.
Figure 6
.
In the Command Prompt window, we will check if Java is successfully installed and running in our system.
To do this, we need to type a command - javac(which calls the Java Compiler) and
press Enter. VoilĂ ! The Java Compiler responds and shows us a set of options that we could use with the javac command.
Figure 7
This concludes a successful setup of the Java environment variables, to run the Java programs. Next in, executing our first Java program.