Class loading process

  • The following diagram depicts the entire process from class loading into the JVM to unloading out of memory.

[Class loading life cycle]

It is divided into five steps: load, connect, initialize, use and uninstall.

  1. Load: Finds and loads the binaries of a class
  2. Connection: Merges binary files that have been read into memory into JVM China
  • Validation: To ensure the correctness of the classes being loaded
  • Preparation: Allocates memory for static variables of the class and initializes them
  • Parse: Convert symbolic references in the constant pool to direct references
  1. Assign initial values to static variables of the class

function

  • Loads the binaries of a class with its fully qualified name
  • Converts the binaries of a class into a runtime data structure for the method area
  • Create a java.lang.Class object on the heap that encapsulates the Class’s data structure in the method area and provides an interface.

Loading way

  • The most common way: load from the local system, archive JAR files
  • Dynamic loading: Compile Java source files into class files
  • Other methods: Load files from network or proprietary databases

Class loader

  • BootstrapClassLoader: Loads the BootstrapClassLoader base module classes
  • PlatformClassLoader: Loads platform-specific classes
  • AppClassLoader: Loads some application-level modules
  • Custom class loader (UserClassLoader) : Users can customize the loading method of classes

Class loader relationships

[Class loading relationship]