Reputation: 436
Why do we need Path and ClassPath? When using IDE's like eclipse we still need to add path ?
Upvotes: 10
Views: 45799
Reputation: 291
let us clear the difference in points:
PATH
a) An environment variable which is used by the operating system to find the executables.
b) PATH is nothing but setting up an environment for operating system. Operating System will look in this PATH for executables.
c) Refers to the system
CLASSPATH
a) An environment variable which is used by the Java compiler to find the path, of classes i.e in J2EE we give the path of jar files.
b) Classpath is nothing but setting up the environment for Java. Java will use to find compiled classes.
c) Refers to the Developing Enviornment.
Upvotes: 3
Reputation: 809
The main difference between PATH and CLASSPATH is that PATH is an environment variable which is used to locate JDK binaries like "java" or "javac" command used to run java program and compile java source file. On the other hand, CLASSPATH, an environment variable is used by System or Application ClassLoader to locate and load compile Java bytecodes stored in the .class file.
For more info: http://www.java67.com/2012/08/what-is-path-and-classpath-in-java-difference.html
Upvotes: 2
Reputation: 926
We don't need to set PATH and CLASSPATH to compile and run java program while using IDE like Eclipse.
These environment variables are required to compile and run java program using CMD.
Example-: Here is the screen shot of console to understand PATH and CLASSPATH quickly
Explanation-:
Compiling the program-
I have java program file Demo.java
stored at location D:\Programs\Classes
. Now I pointed location to D:\Programs\Classes
in CMD and executed javac Demo.java command. System will understand javac
with the help of PATH variable. Java program Demo.java
is complied successfully because PATH is set correctly to %JAVA_HOME%\bin
.
Running the program (class file)-
Since class file has been generated at the same location D:\Programs\Classes
, so we can run this class file by typing command java Demo as displayed in second line in the screenshot. Now system will find the class file with the help of CLASSPATH since my CLASSPATH variable has D:\Programs\Classes
path.
It's not required to point class file location in CMD to run it. System will understand java command with the help of PATH variable and find that class using CLASSPATH variable to run it.
Upvotes: 9
Reputation: 81
path is a mediator between developer and operating system to inform binary file path where as Classpath is a mediator between developer and compiler to inform the library file path those are used in our source code
Upvotes: 8
Reputation: 12817
PATH is the environment variable where we specify the locations of binaries.
Example: We add bin directory path of JDK or JRE, so that any binaries under the directory can be accessed directly without specifying absolute path.
CLASSPATH is the path for Java application where the classes you compiled will be available.
Upvotes: 0
Reputation: 11
Path and Classpath both are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.
Upvotes: 1
Reputation: 3573
path : it is location of bin files(binary executable files) example- java.exe,javac.exe
classPath: it is location of your .class file(which is created after compile your java source file)
Upvotes: 1
Reputation: 1
Difference between path and classpath
Difference between path and classpath in Java
path is set for use java tool in your java program like java, javac, javap. javac are used for compile the code. and classpath are used for use predefined class in your program for example use scanner class in your program for this you need to set classpath.
http://www.tutorial4us.com/java/difference-between-path-and-classpath
Upvotes: 0
Reputation: 489
The path points to the location of the jre i.e. the java binary files such as the jvm and necessary libraries. The classpath points to the classes you developed so that the jvm can find them and load them when you run your product.
So essentially you need the path to find java so it can then find your classes and run them from the classpath
Upvotes: 5