The classpath lists places where the Java runtime should look for classes and resources. The classpath is also used by the Java compiler to find previously compiled and external dependencies.
Java class loading
The JVM (Java Virtual Machine) will load classes as and when the classes are required (this is called lazy-loading). Locations of the classes to be used are specified in three places:-
jre/lib/ext/
)Classes are loaded using classes that are subtypes of java.lang.ClassLoader
. This described in a more detail in this Topic: http://stackoverflow.com/documentation/java/5443/classloaders.
Classpath
The classpath is a parameter used by the JVM or compiler which specifies the locations of user-defined classes and packages. This can be set in the command line as with most of these examples or through an environmental variable (CLASSPATH
)