Because class loaders exist, the Java run time does not need to know
anything about files and file systems when running Java programs.
A class loader starts by being a subclass of java.lang.ClassLoader. The only
abstract method that must be implemented is loadClass(). The flow of
loadClass() is as follows:
Verify class name.
Check to see if the class requested has already been loaded.
Check to see if the class is a “system” class.
Attempt to fetch the class from this class loader’s repository.
Define the class for the VM.
Resolve the class.
Return the class to the caller.
In Java, a class is identified by its fully qualified class name. The fully
qualified class name consists of the package name and the class name. But a
class is uniquely identified in a JVM using its fully qualified class name
along with the instance of the ClassLoader that loaded the class . Thus, if
a class named Cl in the package Pg is loaded by an instance kl1 of the class
loader KlassLoader, the class instance of C1, i.e. C1.class is keyed in the
JVM as (Cl, Pg, kl1). This means that the two class loader instances (Cl, Pg,
kl1) and (Cl, Pg, kl2) are not one and the same, and classes loaded by them
are also completely different and not type-compatible to each other.
例如:图 _MultipleClassLoader s loading the same Target class in the same
JVM _
Target target3 = (Target) target2;
在运行时会抛出ClassCastException
http://onjava.com/pub/a/onjava/2005/01/26/classloading.html?page=1
http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth.html?page=1
http://www.ibm.com/developerworks/java/tutorials/j-classloader/