After installation of java on your computer system is complete you need to think about setting up environment variables like path and classpath.
But before we do so we need to answer two questions:
What these variables are?
Why they are needed?
Let’s find out our answer in individual section explained below.
PATH is a system environment variable.
Java application will run normally even if PATH environment variable is not set.
Only problem will be that every time you wish to run the executables like javac.exe from any directory then you need to type full path to the executable as below:
But if PATH environment variable is set then you can save yourself from the pain of typing the full path each time you run the executables. In this case writing the below command will do the same job as the above command:
C:\ javac HelloWorld.java
It is useful to set PATH environment variable permanently so that it is not forgotten after rebooting of system. You can do this from Control Panel.
Follow the below instruction to set PATH on Windows OS:
Go to Control Panel\System and Security\System
Click on Advanced system settings
Go to Advanced tab
In the System variables section you can see Path as variable name. You can edit or update it and if it doesn’t exist you can create new.
Suppose java on your system is installed at path: C:\Java\jdk1.7.0\bin
Variable value: C:\Java\jdk1.7.0\bin
Just like PATH, Classpath is also a system environment variable.
Java compiler and JVM use classpath to track the location of the class files.
If classpath is set correctly then it should be able to find any java classes that the programmer has compiled using javac command.
Default value of classpath is "." which means only current directory is searched.