Let's see how to set up 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 windows command sysdm.cpl and press the Enter button to open 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 , in order to set the environment variables for executing 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 Edit button, to edit the value of this Path System variable.
Clicking the Edit button to edit the value of 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 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 to open the Command Prompt window.
In the Command Prompt window, we will check whether Java is successfully installed and running in our system.
To do this, we just need to type a command javac(which calls the Java Compiler) and
press Enter. Voilà! Java Compiler responds and shows us a set of options that we could use with the javac command.
This concludes the successful setup of the environment variables of Java, to run the Java programs. Next in, executing our first Java program.