Class Loader
    
    class Load definition: Gets the action of the required class by obtaining a binary stream describing this class through the fully qualified name of a class        
classes start from being loaded into virtual machine memory and are divided into the following 
7 phases to unload the memory 
life cycle :
    ( Loading), 
"validation (verification), preparation (preparation), parsing (Resolution)" , initialization (initializatio n) (using), uninstall (unloading)
    verify, prepare, and resolve collectively referred to as connections (linking)
    
the 
Active reference (the reference that will trigger the class initialization):
    1. When encountering the 4 instructions of new,getstatic,putstatic or invokestatic, if the class is not initialized it will be triggered to initialize (when the 
new object is read, or when the class static field is set, the class static method is called) 
    2. When reflection calls a class
    3. Initialize the class when its parent class is not initialized when the parent class is initialized
    4. When the virtual machine starts, the user needs to specify a main class to execute (the class that contains the main method), and the virtual machines initialize the class first
 
Passive referencing (does not trigger class initializationuse):    1. Referencing a static field of a parent class through a subclass
    2. Referencing a class by defining an array
    3. Static constants of Class B are used in Class A, where Class B is not initialized. Constants are stored in the constant pool of the calling class at compile-time, and the classes that define the constants are not essentially called directly
        
 Parent Delegation Model:     1. The virtual machine's perspective looks like the class loader type:
            A. Start the class loader (Bootstrap ClassLoader), implemented in C + +. 
            B. All other class loaders are implemented by Java. And all inherit from the Java.lang.ClassLoader class
    2. Developer's point of view class loader type:
            A. Start the ClassLoader (Bootstrap ClassLoader): Responsible for loading the <java_home>/lib directory. 
(identified by file name) 
            B. Extension class loader (Extension ClassLoader): This ClassLoader is implemented by 
Sun.misc.launcher$extclassloader , which is responsible for loading <java_home>/ All class libraries in the Lib/ext directory, or in the path specified by the JAVA.EXT.DIRS system variable
            C. Application class loader (Application ClassLoader): This ClassLoader is implemented by Sun.misc.launcher$appclassloader, Since the return value of ClassLoader's Getsystemclassloader method is also it, it is generally referred to as the system loader. 
     
working process: 
        if a class receives a request for a class load, it first does not attempt to load the class itself, but instead delegates the request to the parent ClassLoader to complete, as is the case for each level of the ClassLoader. 
so all class load requests should eventually be routed to the top-level startup class loader, and the child loader will try to load itself only when the parent loader has feedback that it cannot complete the load request. 
    
    Benefits of parental delegation Model:
        1.[stability] the same class will always load the same classloader, for example Java.lang.Object in Rt.jar. Then in various classloader environments will be delegated to the startup ClassLoader, so there will only be one OBJEC class in the system
    
        ClassLoader Implementation of parental delegation model source code:
The/*** uses the specified binary name to load the class. The default implementation of this method searches for the class in the following order: 1. Call Findloadedclass (String) to check whether the class has been loaded. 2. Call the LoadClass method on the parent class loader. If the parent ClassLoader is NULL, the built-in class loader for the virtual machine is used. 3. Call the Findclass (String) method to find the class. If the class is found using the steps above, and the resolve flag is true, this method calls the Resolveclass (Class) method on the resulting class object. It is encouraged to rewrite Findclass (String) with ClassLoader subclasses, instead of using this method, ClassLoader's Findclass method defaults to throwing classnotfoundexception**/protected Class<?> loadclass (String name, Boolean resolve) throws ClassNotFoundException {synchronized (GetC Lassloadinglock (name)) {//First, check if the class has already been loaded class C = FINDLOADEDCL            (name);                if (c = = null) {Long T0 = System.nanotime ();                    try {if (parent! = null) {c = Parent.loadclass (name, false);                    } else {c = findbootstrapclassornull (name); }} catch (ClassNotFoundException e) {//ClassNotFoundExceptionThrown if class not found//from the Non-null parent class loader} if ( c = = null) {//If still not found, then invoke Findclass in order//to find the CL                    The.                    Long T1 = System.nanotime ();                    c = findclass (name); This is the defining class loader;                    Record the stats sun.misc.PerfCounter.getParentDelegationTime (). Addtime (T1-T0);                    Sun.misc.PerfCounter.getFindClassTime (). Addelapsedtimefrom (t1);                Sun.misc.PerfCounter.getFindClasses (). increment ();            }} if (resolve) {resolveclass (c);        } return C; }    }
 
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
 
03-Class Loader