method area: class information, class variables (static variables and constants), methods
heap: object, member variable
stacks: local variables
(1) When the program is run, the bytecode file is loaded first through the class loader, and after parsing, loading the method area! Various information about classes is stored in the method area, including class variables, class constants, and methods. For calls to the same method, different instances of the same class are called the same method that exists in the method area. The life cycle of a class variable is created from the time the program starts running and ends when the program terminates!
(2) When a new object is in the program, the object exists in the heap, The object's variable exists in the stack, pointing to the reference in the heap! The member variables of the object are present in the heap, and when the object is recycled, the object's member variable disappears!
(3) When the method is called, the JVM assigns a stack frame to the stack, The local variable that stores the method. When the method call ends, the local variable disappears!
Class variables: attribute information that belongs to a class, regardless of the instance of the class, where multiple instances share the same class variable, and exist in the method area. The class variable is decorated with static, which includes statics and constants. Static variables have default initial values, and constants must be declared and initialized at the same time.
Member variable: A variable belonging to an instance, only relevant to an instance, written under a class, outside of a method, not static decorated. Member variables survive as members are created and are destroyed as members are recycled.
Local variables: Declared in a method, there is no default initial value, which is created with the invocation of the method, stored in the stack, and destroyed as the end of the method call.
Java heap, stack, method area/class variable, member variable, local variable