Java: Java instantiation (new) process

Examples of process (new)

1. First District JVM process to find the class object class area, if found, in accordance with the definition generated object not found >> 2 shown below

2. Load the class definition: class loader (classLoader) looking for class .class file, parse the file converted to class objects into the future to find a convenient way to call the district.

Wherein the loading is completed with the boot class loader when the class is typically jdk JVM starts, the user class is used when reloading.

 

 

Java ClassLoader loaded in the delegation mechanism adopted parents, adopted parents when the delegation mechanism to load the class few steps as follows :
1. The current ClassLoader first check whether these have been loaded they have loaded from the class, if already loaded directly return the already loaded class.
Each class has its own loader loads the cache, when a class is loaded into the cache will be later, so next time you can load directly returned.
2. Current classLoader not found in the cache loaded class, commissioned by the parent class loader to load, the parent class loader using the same strategy, first check its cache, then delegate the parent class of the parent class to load, has been ClassLoader to bootstrp.
3. when all the parent class loader are not loaded, and then loaded by the current class loader, and placed in its own cache, so next time there is a load request return directly.
Here you might think, Java why should such a delegation mechanism? Understand this issue, we introduce another concept about Classloader the "namespace", it is simply more to determine whether a class, fully qualified name of the class and the need to load the ClassLoader of this class to jointly determine. In other words, even if the fully qualified name of the two classes are the same, but because of the different kind of ClassLoader loaded, then the JVM it is different class. Understand namespaces later, we look at the delegation model. Uses a delegation model after increasing the ability to interact with different ClassLoader, such as said above, we provide Bunsen JDK class library, such as hashmap, linkedlist and so on, these classes loaded by the class loader bootstrp later, whether you program in how many class loader, then these classes are in fact can be shared, thus avoiding different class loader loads the different classes of the same name later cause confusion.

 

Open memory space (object initialization) jvm heap to the subject in the following order:

(1) static objects parent class, static code block

(2) static objects subclass, static code block

(3) non-static objects parent class, non-static block

(4) the parent class constructor

(5) a subclass of non-static objects, non-static block

(6) subclass constructor

 

 


Article reprint to: https: //blog.csdn.net/qq_25269997/article/details/77429730

Guess you like

Origin www.cnblogs.com/nhdlb/p/12169361.html