Started just three enough
java stored way
1. Register
2. Stack (Stack)
3. heap (heap)
4. Static field
5. The constant pool
6. Non RAM memory
A stack
Storing variable data objects and types of basic reference.
When the program enters a method, this method will be assigned to a separate genus private storage space,
local variables to store internal this method,
when the end of this method, this method is assigned to the stack is released,
the stack variables It will also be released.
Second, the heap
Objects created using new storage, global variables.
The method of storing data that is not in the current stack
Third, the constant pool
Basic types of string constants and constants (public static final)
Explanation
String a ="zouyun";
String b="zouyun";
String c=new String("zouyun2");
String d=new String("zouyun2");
String is a reference type,
which is a reference to the presence of the stack, creating a "zouyun" in the constant pool
b is a reference to the presence of the stack, has been in existence since the constant pool "zouyun", so no constant pool continues to create objects.
Where c is a reference stored on the stack, new String objects stored in the heap, create "zouyun2" objects in the constant pool.
d reference is stored on the stack, new String object is stored on the heap, I found "zouyun2" in the constant pool so do not create the object.