The classloader simply loads a class file into JVM memory with the specified fully qualified name and turns it into a class object.

  • Bootstrap ClassLoader, implemented in C++ (for HotSpot), loads into memory libraries stored in the

    \lib directory or in the path specified by the -xbootclasspath parameter.

  • The Extension ClassLoader is responsible for loading all class libraries in the

    \lib\ext directory or in the path specified by the java.ext.dirs system variable.

  • The Application ClassLoader is responsible for loading the specified class libraries on the user’s classpath, and we can use this ClassLoader directly. In general, if we don’t have a custom class loader this is the default.

  • If a class loader receives a request for a class load, it first does not attempt to load the class itself. Instead, it delegates the request to the parent class loader. This is true for every classloader, and only if the parent cannot find the specified class in its search scope (that is, ClassNotFoundException) will the child loader attempt to load it itself.

Why do we need the parental delegation model?

  • Protect JDK native class security, to prevent malicious rewrite
  • Makes a Java class have a hierarchical relationship with priority along with its classloader.

bootstrapClassLoader

ExtClassLoader

AppClassLoader

Custom ClassLoader