classpath is a environment variable which is used by JRE(Java Runtime Enviroment) to find out the location of user defined packages and classes.

To complete the execution of any class , JRE uses predefined classes and user defined classes.

Location of predefined library is already fixed and known by the JRE but the location of user defined package folder is not fixed and not known by the JRE , hence classpath environment variable is used to define the location of user defined package folder to the JRE.

  • Difference between PATH and CLASSPATH in Java

    Let us see:

    path classpath
    PATH is an environment variable which is used by Operating System to find out the location of executable files like "java" or "javac" , which is used to run java program and compile java source file. CLASSPATH is an environment variable used by ClassLoader(JRE) to find out the location of user defined packages and classes.
    In order to set PATH in Java, you need to include JDK_HOME/bin directory in PATH environment variable , which is fixed . In order to set CLASSPATH in Java you need to include all those directories where you have put either your .class file or JAR file which is required by your Java application.
    PATH can not be overridden by any Java settings . CLASSPATH can be overridden by providing command line option -classpath or -cp to both "java" and "javac" commands.

What next?

The next topic is static import in java

Share this page