The classloader acts as a porter, moving.class files into the JVM.

Class loader

JVM built-in three classloaders, except bootstrapClassLoader other classLoader is implemented by Java, and inherited from java.lang. classLoader

  • BootstrapClassLoader: Launches the class loader, the C ++ implementation, which is the top-level class loader. It is responsible for loading the JAR in the javahome/bin directory or all classes in the path specified by the -xbootclasspath parameter.
  • ExtensionClassLoader: It is responsible for loading JARs in the jreHome/lib/ext directory or in the path specified by the java.ext.dirs system variable
  • AppClassLoader: The application classloader that loads the JARs in the current application classpath.

Parental delegate model

Each class has a corresponding classloader.

When a class is loaded, it will determine whether the current class has been loaded or not. Classes that have been loaded will be returned directly. If not loaded, it will determine whether its parent class has been loaded. It has not been loaded at all. It will delegate to the superclass loader to handle it. If the superclass loader fails to handle it, it will handle it itself.

So all requests are eventually passed to the bootstrapClassLoader.

When the parent class loader is null, the BootstrapClassLoader is used as the loader.

Benefits of the parental delegate model

You can avoid class reloading. Because the same class is loaded by different loaders, two different classes are produced.