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 -
Hence, the path of the bin folder in JDK in our system is -
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.
Once the window of System properties opens up, we need to click on its tab that says, Advanced.
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.
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.
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.
Next, click the OK button on the previous window of Environment Variables, to save and apply the changes.
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.
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.
This concludes a successful setup of the Java environment variables, to run the Java programs. Next in, executing our first Java program.