In this article we will take a comprehensive look at what path and classpath in the JAVA programming language is and we will look into the vast differences between the two.
Necessity of path and classpath:
To compile and use a program written in Java we use a two very useful tools, namely , the javac and java tool. But how is it decided where these tools are located in our hard-disk so that it can accessed when required? It is the Path that provides these necessary locations. In a similar fashion , the classpath provides the directory location where are all the classes pertaining to a given program is stored.
One way to differentiate path and classpath is by examining who uses each of these variables. The path is used by the operating system while the class path is used by the java compiler. Therefore in order to use the java compiler, the operating system uses the path variable and to use the classes of a program the java compiler uses the classpath variable.
Another way to separate path and classpath is by reviewing the possibility of overriding each of these commands. It is possible to override the classpath variable through the -cp command from the shell or by modifying the manifest file. However it is not possible to override the path variable by any known method.
The last method to illustrate the dissimilarity of path and classpath is simply by looking at the Java Folder Hierarchy. In this sense , the path variable usually points to the bin folder while the classpath variable by default points to lib folder. There is also a difference in the commands that are to be used to display the classpath and path. In windows , the path can be displayed by using the command – “
echo %path%” – while the classpath can be viewed by using the command – “