What is path setting
We can write a java program in any editor such as notepad etc, and compile it.The compiler of the java technology (javac.exe) is in the bin directory.The bin directory also contains other .exe files. Location of java compiler is C:\program files\java\jdk\bin.
Setting Path Variable
We can store the program in any location on our computer such D: or E:. We can run it by saving the notepad file with .java extension and with the command prompt compile and run our java program.If we don’t set the path of javac.exe then on running the program we get the following output on command prompt:
On UNIX– javac: Command not found.
So to compile the program and remove the error we have to set the path. It simply means that directing the computer to search javac.exe in JDK. There are two methods of setting path in java.
- Temporary:It sets the path through cmd using set path command.
- Permanent:It sets the path by adding a new environment variable in system settings
Temporary Path Setting
It can be done by using the set path command in the command prompt.Open cmd and write set path=”C:\Program files\java\jdk1.6.0\bin”.The URL may differ so open the bin folder in your JDK,copy the URL and paste it in set path command.
This path is set only while the command prompt is running.Once it is closed and started again we have to set the path once more.It is time consuming for the user so a permanent path setting method is developed.
Permanent Path Setting
In this method we add an environment variable in system settings and store it. So this is a permanent method. Right click on my computer and go to properties.Then click on advanced system settings. A window will appear.
Click on environment variables and then click on user variables.If there already exists a variable named path then delete it.Otherwise click on new to add a variable.
Write name and change the variable value to URL of java compiler. Click on ok. The path has been set for javac permanently.