1. Register
This is the fastest storage area because it is located inside the processor. However, because the size of the register is limited, the register is allocated by the compiler on demand. You cannot directly control or feel the presence of a register.
2. Stack
is located in general-purpose RAM (random access memory), but can receive direct support from the processor through the "stack pointer". By moving the stack pointer up and down to allocate the required space for the program, its speed is only second to the register speed. When you create a program, the Java compiler must know the exact size and lifecycle of all the data stored in the stack, because it must generate the appropriate code to move the pointer up and down. Such a restriction largely limits the flexibility of the program. So Java, while some of the data is stored on the stack (object references), the actual Java objects are not stored in the stack, but are stored in the heap.
3. Heap
resides in RAM due to storing Java objects. The benefit of a heap that differs from the stack is that the compiler does not need to know the size and life cycle of the space required by the program data. Therefore, the object can be directly new and automatically allocated memory in the heap when executed. This makes the process relatively flexible. But the problem is that allocating a heap for memory allocation takes more time than storing the stack (which is one of the reasons everyone says Java is slow).
4. Static storage
Located in RAM, corresponds to a specific element of an object identified by the static keyword in java. Static refers to: in a fixed position
5. Constant storage
Constant values are usually stored directly inside the program code.
6, non-RAM storage
If the data exists outside the program, it can be free from any control of the program and can exist when the program is not running, corresponding to the "stream object" and "persisted object" in Java.
Thinking in java--object storage location