Java foundation - Object

Q1: What operating with objects?

A1: handle, namely Handle, and then put it another way, references, and even pointers.

 

Q2: Objects stored?

A2: nothing more general objects stored in these local areas: a register stack, stack, static memory, ROM, non-RAM memory (such as a byte stream); in Java, heap and stack in main storage, specifically method escape into (a heap), escapes the thread (a heap), and no escape (stored on the stack) in three ways.

 

Q3: initialize the object?

A3: object can be divided into static and non-static two kinds, two kinds of object initialization sequence is not the same.

On the macro level, it is assumed that there are two kinds of objects:

The overall sequence is the first after the first static non-static group in this class

Specifically static field is initialized to the base class, then initialize the static fields in this class, the base class and then to non-static, and then this non-static class, after performing the base class constructor, then this class constructor performs.

Microscopic observation, in-depth understanding of jvm also has said before, Java interpreter first class search path, locate class files, load class object, creating an object class, then initialize static objects, when using the new keyword, first in the heap the allocation of space, space after all clear that the null, then starts to initialize non-static objects, and then execute the constructor.

 

Q4: Features static object created?

Static variable definitions, if basic types, such as char, int, etc., according to the standard value of its initial assignment, if a handle to an object, unless a new object is connected, or is null.

If the initialization simultaneously defined, non-static with similar, but the difference is only a static storage area, and initialized only once, this process occurs when the Class object is first loaded.

Guess you like

Origin www.cnblogs.com/Yintianhao/p/12113113.html