The class initialization phase is the last step in the loading process, where the variable has already assigned the initial value of the system requirement, and during the initialization phase, the class variables and other resources are initialized according to the programmer's subjective plan, or from another angle: the initialization stage is the execution class constructor < The process of the clint> () method.
The <clint> () method is generated by the combination of the assignment of all class variables in the compiler's automatic collection of classes and the statements in the static statement block (static ()), which are collected by the compiler in the order in which the statements appear in the source file, statically
determined by the order.
The <clinit> () method differs from the parent class constructor (or instance constructor <init> method) in that it does not require a display to call the parent class constructor, and the virtual opportunity guarantees that the parent class's < before the subclass's <clinit> method executes. The Clint> () method has been executed. So the first <clinit> () method that is executed in the virtual machine is definitely java.lang.Object.
Because the <clinit> () method of the parent class executes first, it means that the static statement block defined in the parent class takes precedence over the variable assignment of the child class.
The <clinit> () method is not necessary for a class or interface, and if there is no static statement block in a class, and there is no assignment to the variable, the compiler can not generate the <clinit> () method for the class.
A static statement block cannot be used in an interface, but there is still an assignment operation that initializes the variable, so the interface generates the <clinit> () method as a class. But interfaces differ from classes in that execution interfaces <clinit> methods do not require
The <clinit> () method of the parent interface is executed first. The parent interface is initialized only if the variables defined in the parent interface are used. In addition, the implementation class of the interface does not execute the <clinit> () method of the interface at initialization time.
Sequence opportunities ensure that a class <clinit> () method is correctly locking, synchronized in a multithreaded environment, if multiple threads are initializing a class at the same time, then only one thread executes the <clinit> () method of the class, and the other
Threads are required to block the wait until the thread execution <clinit> () method is complete.
Java Virtual machine class load phase-initialization (initialization)