In order to improve the efficiency of the program, the Java program makes different spatial allocations to the data:
The specific partition is the following 5 memory allocation methods:
1. Stack: Local variables are stored
2. Heap: All new things are stored
3. Method Area:
4. Local Method Area: (and system-related)
5. Register: (CPU use)
Local variable: A variable in a method definition or a method declaration is called a local variable
Features of heap Memory:
1. Every new thing that comes out has an address value.
2. Each variable has a default value
Byte,short,int,long is 0
Float,double is 0.0
Char "\u0000" is equivalent to null
Reference type is NULL
3. It will become garbage when it is finished, but it will not be collected immediately, and may be recycled when the garbage collector is idle.
Features of stack memory:
Data is freed from scope
The value of the array name is the address, and the value of the array element (that is, the array name [index]) is the value that stores the data in the array.
int[] Arr3 = arr; This is the address of ARR to ARR3, now the same as the first address of ARR and ARR3.
ArrayIndexOutOfBoundsException: Array index out-of-bounds exception
Cause: A non-existent index was accessed
NullPointerException: null pointer exception
Cause: The value of the array name is null and no longer points to the address value. You also use the array name to access its elements.
Array property: Length, used to get the length of the array.
Format: array name. length
Java Memory allocation