Difference between PATH and CLASSPATH in Java

PATH and CLASSPATH are operating system level environment variables. PATH is used to define where the system can find the executables (.exe) files whereas CLASSPATH is used to specify the location of .class files.

Whenever you type something into a command prompt, if it is not a system command, it will searches in that directory that you have already added in the PATH variable.


Example 1:



This is because of “notepad.exe” file is in “C:\Windows\system32″ location. And this path is already set in PATH variable.


Example 2:

In command prompt, when you type “eclipse”


This is because of “eclipse” is neither system command nor its path is set into PATH environment variable. So if you want to run eclipse from here then you have to set its path into PATH variable.


After setting eclipse path into PATH environment variable, you can run eclipse from your command prompt at any location.



CLASSPATH is different from PATH. CLASSPATH is used by the JVM that tells the JVM where to find the class libraries, including user-defined classes and libraries to import or interpret at compile time or run time.

The CLASSPATH is a list of locations, where the JVM will search for classes (jars and directories).

If the CLASSPATH is set as

Environment Variable Name = “CLASSPATH”

Environment Variable Value = “D:\classesslocation;D:\jarslocation\abc.jar”

JVM will search Classes in “D:\classesslocation” or in “D:\jarslocation\abc.jar”


@NOTE: PATH environment variable is used by operating system; this is true for both Windows and Linux environment while CLASSPATH is used by Java ClassLoaders to load class files.