1. Registers
This is the fastest storage area within the processor and cannot be directly controlled.
2. Stacks
In RAM, the stack pointer moves down to allocate new memory, and the stack pointer moves up to free memory. Storage speed is second only to memory.
When you create a program, the Java system must know the life cycle of all items stored in the stack so that the stack pointer moves up or down. typically used to hold object references, objects are not stored on the stack.
* Exceptions: Java primitive type, instead of creating a variable with new, create an "automatic" variable that is not a reference. This variable stores the value directly and places it on the stack. The base type stores the actual value, not the object's reference.
3. Heap
Used to store Java objects. The advantage is that the compiler does not need to know how long the stored data will survive in the heap, and when an object is needed, the storage allocation is automatically made in the heap.
4. Constant storage
Placed directly inside the program code.
5. Non-RAM storage
The data is completely out of the program and can exist if the program is not running. such as stream objects and persisted objects.
Java stores data in several places