Table of Contents
In this post , we will see differences between PATH and CLASSPATH in java.
Let me provide simple definition about PATH and CLASSPATH.
PATH :
This is environment variable which operating system uses to locate executable such as javac, java, javah,jar etc.
For example: bin directory of jdk has all the executable such as javac,java so we can set upto bin folder.
1 2 3 |
"C:Program FilesJavajdk1.7.1bin" |
CLASSPATH:
This is environment variable which java virtual machine (JVM) uses to locate all classes which is used by the program.
For example: jre/lib/rt.jar has all java classes and you also need to include jar files or class file which is being used by program.
1 2 3 |
"C:Program FilesJavajre1.7.1jrelibrt.jar" |
PATH vs CLASSPATH:
Parameter
|
Path
|
classpath
|
Locate
|
It allows operating system to locate executable such as javac, java |
It allows classloader to locate all .class file used by program
|
Overriding
|
You can not override path variable with java setting |
You can override classpath by using -cp with java,javac or class-path in manifest file.
|
Inclusion
|
You need to include bin folder of jdk (For example jdk1.7.1/bin)
|
You need to include all the classes which is required by program
|
Used by
|
Operating system
|
java classloaders
|
You can go through top 50 core java interview questions for more such questions.