Open In App

Difference Between Path and ClassPath in Java

Improve
Improve
Like Article
Like
Save
Share
Report

The ClassPath is a parameter in the Java Virtual Machine(JVM) or the Java compiler that is used by a system or application ClassLoader to locate and load compiled Java bytecodes stored in the “.class” file. On the other hand, The Path is also an environment variable path that behaves as a mediator between the operating system and developer to inform binary file path.

Path

PATH is an environment variable that is used to find and locate binary files like “java” and “javac” and to locate needed executables from the command line or Terminal window. To set the path, we’re supposed to include or mention JDK_HOME/bin directory in a PATH environment variable. The PATH can not be overridden by providing command and PATH is only used by the operation system(OS) to find binary files.

Syntax

// To set PATH in the window OS.
set PATH=%PATH%;C:\Program Files\Java\JDK1.5.10\bin

// To set PATH in Unix OS
export PATH=${PATH}:/opt/Java/JDK1.5.10/bin 

Classpath

Classpath is an environment variable that is used by the application ClassLoader or system to locate and load the compiled Java bytecodes stored in the .class file. To set CLASSPATH. the CLASSPATH can be overridden by adding classpath in the manifest file and by using a command like set -classpath. the CLASSPATH is only used by Java ClassLoaders to load class files.

Syntax

// To set CLASSPATH in window OS.
set CLASSPATH=%CLASSPATH%;C:\Program Files\Java\JDK1.5.10\lib

// To set PATH in Unix OS.
export CLASSPATH=${CLASSPATH}:/opt/Java/JDK1.5.10/lib

The following table demonstrates the difference between a PATH and a CLASSPATH

S. No. 

PATH 

CLASSPATH

1.

An environment variable is used by the operating system to find the executable files. An environment variable is used by the Java compiler to find the path of classes.

2.

PATH setting up an environment for the operating system. Operating System will look in this PATH for executables. Classpath setting up the environment for Java. Java will use to find compiled classes.

3.

Refers to the operating system. Refers to the Developing Environment.

4.

In path variable, we must place .\bin folder path  In classpath, we must place .\lib\jar file or directory path in which .java file is available.

5.

PATH is used by CMD prompt to find binary files. CLASSPATH is used by the compiler and JVM to find library files.

Last Updated : 30 Jan, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads