First above:

ClassLoader:

ClassLoader exists as a transporter that streams local hard disk/network class files into the JVM’s method area, forming DNA metadata templates known as method areas (metadata areas in JDK8.0).

Note: String constant pools and static variables are stored in the heap, which can be seen in the JVM- method area documentation.

Class loader type:

BootstapClassLoader (BootstapClassLoader) : written in C, loads the core library

ExtClassLoader: loads the class libraries in the extension directory

SystemClassLoader: application classes are usually loaded with this loader.

Custom loader: Exists as an extension.

Relationships between class loaders: Not parent-child relationships, but containment relationships, such as ExtClassLoader containing the BootstapClasLoader object.

Why this process loader? This involves parental delegation.

Parent delegate mechanism: protects Java core library classes from being overwritten

Java virtual machines load class files on demand, using the parent delegation mode, that is, the request to the parent class processing, is a kind of task delegation mode.

Working principle:

First delegate up until the boot class loader, if the upper loader cannot load, then down to the child loader to try to load, once loaded to the class, it will return successfully.

Advantages of parental delegation:

Avoid reloading classes

Protect program security and prevent the core API from being tampered with.

Three steps of loading:

1, Loading

The generated Class object, which is stored in the heap, is also an object through which all the information in the method area can be associated, which is how reflection works. The Class Class has a ForName(String className). You can get the corresponding Class object through the path, and then get the generated object or the corresponding object properties, methods, and so on.

B. Linking

  • Verification: Verifies whether the bytecode file is valid.
  • Preparation: Allocates space for class variables (except those modified by final Static) and gives default values.
  • Parse: Convert symbolic references to direct references.

3. Initialization

Class constructor methods (Clinit) – This is automatically generated at compile time (holding static variables and static code blocks, executed in the order they appear in the source file)

The constructor method of a class (init) — what we call a constructor — is defined from a virtual machine perspective.

There is an illegal forward reference. I don’t understand it. If you have a clear friend, can you leave a message? Thanks a lot!

Other notes on class:

Class name +classLoader

Active and passive loading of classes:

Difference: Passive loading does not perform initialization steps