Setting PATH and CLASSPATH are two different task in Java. Let me make you more clear about PATH setting and CLASSPATH setting in Java. If you had missed your lectures on PATH setting then this post will make you clear view about PATH setting .
PATH ---> It is the path indicating the lists of all java executable files which will be use to run our java programs.
CLASSPATH ----> It is the path indicating the lists of all class file of the users, it has nothing to do with java predefined classes. It only indicates where the user class file is present.
What is the need of setting PATH ?
PATH is a system variable predefined in the windows OS . It must be written in capital letters and we need of set path of the Java executable files ( like Javac.exe, java.exe , javadoc.exe etc ). It is because unless we set the path we can't be able to run the java program.
Now you must be thinking of that ,
Is it possible to run java programs without setting the path ?
Answer is yes, you can but you have to set the path every time when you run your program . like this,
C:\Java\jdk1.5.0\bin\javac File_name.javaSo instead of writing full path every time while running your program, its better to set the PATH for the java compiler and interpreter so that u will not have to write it again and again while running your java program.
What is the need of setting CLASSPATH ?
Like PATH environment variable it is also a predefined system variable in window OS. By setting CLASSPATH it indicates that users class file are present on that path and then user are eligible to run their .class file from any where through command prompt.
But it is not recommended to set CLASSPATH because in future user may wants to keep their .class file in other location , now that time again we need to change our CLASSAPTH. So it would be best to set CLASSPATH manually while running the program. For this all we need to do is ---
set CLASSPATH=path_name;
How to set the PATH in Java ?
Setting the path in Java means specifically we are going to set the path for the java compiler known as javac and java interpreter known as java. Unless we set the path we can't be able to run and interpret the java program or we can use java compiler by setting it while running the program but it is tedious as i mentioned above in " What is the need of setting path? " section .
Now i am going to show you how to set the path in java through some snapshots so that it will be easy for you understand. Here we follow step by step . Its a very easy task and matter of only few minutes and you are done !
Step 1 > Install the Java which is available in different versions like java 4, java 5, java 6 ,java 7 .But it is recommended to install java 5 because many new concepts are introduced from java 5, which you will fail to operate through java 4.
It will be best to install JDK 5 from its official website . Here is the Link just have a click on it Click here for all version of JDK .
After installing Java a folder named Java is being created in program files , where you will find two folders names JDK < version_name> and JRE .
Step 2 > After installing we need to copy the path of a bin folder created where all the executable files of java are present , have to post it to the PATH environment variable.
Here are the snapshots for copying the path for Java compiler. Follow each snapshots and then you are done with copying the path !
b) Select the Program file folder
c) Now select Java Folder
D) After Clicking on Java folder you can see two folder one is JDK and another one is JRE Then you have to select JDK folder and open it by double clicking.
E) After clicking you can see that there is bin folder which is your required folder , now select this folder !
E) After clicking on bin a window will open all you need to click on the path bar and copy the path !
Now here in this last snapshot you can see that there is a executable file named as javac which is known as Java Compiler . It is only responsible for compiling the java programs.
Now here there is another executable file named as java just above the javac which is known as java interpreter and is work as an interpreter which is a task of JVM( Java Virtual Machine ) .
So after copying the following path we need to paste it to the actual place where we set the PATH variable .
For setting up PATH variable see the following snapshots.
A) Right click on Computer and select the properties option .
B) This window appear after clicking on Properties option and now click on the Advanced Setting option( on the left panel of the window)C) Here select the Environmental Variables Button .D) Here in the below image you can see there in no PATH variable available , there is nothing to worry just click on NEW button a window will open with two blank space available.Note: If you have PATH variable then you just need to edit the path by clicking on EDIT option and paste the copied path to the variable value section by removing the previously written text on it and don't forget to terminate it with semicolon( ; ) . Unless you terminate with semi-colon it won't work. So be careful and make sure it must be terminated with semi-colon.E) Now You just need to write PATH in Variable name section and the path which you copied from bin folder need to paste it in variable value section and terminate it semi-colon as you see in the above image .Then click on OK button. F) After clicking on OK button in the above image the window appear will look like the below image that means you are successfully done. Now click on OK button and you are done with it ! How simple it was !
Step 3 > Now to check whether you have successfully set the path or not just need to open the command prompt and simply write javac command. Now if java have been installed successfully and also path have been set then it show the following message after running the javac command.
If its come like this then you are done setting path successfully. If it is not coming like this then you must have done some mistakes or you may missed out some point . So re-check the following steps.
Now enjoy compiling and running java programs !
EmoticonEmoticon