A variable of a primitive type, if defined, allocates memory space, regardless of whether it is assigned, or if it is a property of an object, so long as the object is not instantiated, no memory space is allocated.
A complete Java program will run with the following memory areas:
1, Register: JVM Internal virtual register, access speed is very fast, the program is not controllable.
2, Stack: Save the values of local variables, including:
1) values used to hold the base data type;
2) Save an instance of the class, which is a reference to the heap area object (pointer)
3) can also be used to save the frame when loading the method
3, Heap: Used to store dynamically generated data, such as new out of the object. Note the objects that are created contain only the member variables that belong to them, and do not include member methods. Because objects of the same class have their own member variables,
stored in their own heap, but they share the method of the class, not every object created to copy the member method once.
4. Chang: The JVM maintains a constant pool for each loaded type, and a constant pool is an ordered set of constants used by this type.
includes direct constants (basic types, String) and symbolic references to other types, methods, and fields (1). The data in the pool is accessed through the same index as the array.
because a constant pool contains symbolic references to other types, methods, and fields for one type, Chang plays a central role in the dynamic linking of Java. A constant pool exists in the heap.
5, Code snippet: used to store the source code read from the hard disk.
6. Data segment: Static member that is used to store the static definition.
For variable problems in Java