Static area constant pool

Static area
Static variables (also called class variables, with static modification) and static methods are stored in the static area;

When using a certain class, you need to load the bytecode file of the class into the metaspace;
in the process of loading, it will first check whether there are static-modified members in the class;
if so, the static-modified members will be given priority Load into the static area.

After the object of the class is created, the object is stored in the heap, and the variable name of the object is stored in the stack frame of the main method on the stack. The stored data is the address of the object in the heap, and the static members of the class are owned by all the classes. The objects are shared, and the modifications are the same
Insert picture description here

==================================================================

The constant pool (in memory)
declares a constant as a and the value is abc. This constant is placed in the constant pool;
when the second constant b is created, it is found that the value is also abc, which is already in the constant pool, so just Let b directly point to abc in the constant pool, so the result of the comparison between the two with == is true.
When creating c, by creating an object, a piece of memory is re-opened for c to store it, so the result of the double equal sign comparison is false.
Insert picture description here

Guess you like

Origin blog.csdn.net/ExceptionCoder/article/details/107505947