When a Java application references Java classes, the Java Virtual Machine (JVM) uses a ClassLoader to load them into memory. The Delegation Model was introduced in Java 2 and organizes ClassLoaders into the following tree/hierarchy by using parent/child relationships, as shown in Figure A-1. Figure A-1. Standard J2SE ClassLoader hierarchyThe J2SE ClassLoaders do the following:
If the current ClassLoader previously loaded a class, then the ClassLoader returns the class to the client. If a class has not been previously loaded, then according to the Java specification, a ClassLoader must defer (or delegate) to its parent before trying to load the class itself. For example, if an application references java.lang.String, the System ClassLoader delegates to the Extension ClassLoader, which in turn defers to the Bootstrap ClassLoader to load the String class. The child ClassLoader gets a chance to load a class only if the parent hasn't already loaded the class or couldn't load the class. A class is loaded only once per ClassLoader. |