Difference between Path and Classpath Environment Variable in Java

Difference between Path and Classpath Environment Variable in Java

Difference between Path and Classpath Environment Variable in Java

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:

  • Path variable
  • Classpath variable

The difference between Path and Classpath environment variable in Java:

Let’s dwell on each of the variable first…

Path Environment Variable in Java

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…

  • java– It is used to run Java program.
  • javac – It allows to compile Java program.
  • javap – It dis-assemble a class file so that it will display end user all the fields, constructors, methods present in the class for the end user.
  • javah – It allows interacting Java application with C code, jar- combined multiple Java files into single jar archive file.
  • appletviewer – It allows to run the applet in Java outside of the web browser.

You can find JDK Hierarchy in the following image. That shows availability of Java tools and classes in JDK directories.

JDK folder Hierarchy to setup Path and Classpath environment variable in Java

Classpath Environment Variable in Java

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.

Path Vs Classpath Environment Variable

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!

Leave a Reply

Your email address will not be published. Required fields are marked *