These are very important variables in Java. Once you have installed Java JDK toolkit, it is necessary to set path & classpath. It is one-time setup that will help you throughout running all Java applications. In this post, we see the difference between path and classpath environment variable in Java.
It is simply variable that contain links to tools and classes provided by JDK system.
There are two types of the environment variable we need to set for Java:
Let’s dwell on each of the variable first…
The path is variable to provide the path of tools that we used while working on any Java program. It contains all the directories path.
There are multiple java tools we use. Some of the important tools we use in java are…
You can find JDK Hierarchy in the following image. That shows availability of Java tools and classes in JDK directories.
It is variable that provides link path to all classes which we require in our application.
For Java, all classes provided by system presents in lib /rt.jar files. So it is very necessary to locate the path of these classes before actually using in our application.
Though both are the environment variable that contains directory paths, there is a difference between path and classpath variables in Java.
Path Environment Variable | Classpath Environment Variable |
---|---|
It contains a path to the java tools. | It contains a path of the classes provided by JDK. |
Java tools include java, javac, javap, javah, jre… | All the classes are available in “rt.jar” file. |
Command to check path: >>echo %path% | Command to check classpath: >>echo %classpath% |
Wrapping up…
I have seen many geeks getting confused on setting up path and classpath variables in Java. I expect from this post you got a complete understanding of the difference between Path and Classpath environment variable in Java.
If you want to setup these two variables in your system for Java, do read step by step complete guide for JDK installtion.
Happy Programming!