Java memory allocation and java allocation
Java programs allocate different spaces for data to improve program efficiency:
The specific division is as follows:
1. STACK: stores local variables.
2. Heap: stores all new things.
3. Method Area:
4. Local Method Area: (related to the system)
5. registers: (CPU usage)
Local variables: variables in the method definition or method declaration are called local variables.
Heap memory features:
1. Each new item 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
The reference type is null.
3. After use, it turns into garbage, but it is not recycled immediately. It will be recycled when the garbage collector is idle.
Stack memory features:
Data is released when it leaves the scope.
The value of the array name is the address, and the value of the array element (that is, the value of the array name [Index]) is the value of the data stored in the array.
Int [] arr3 = arr; // This is to give the arr address to arr3, and now the first address of arr is the same as that of arr3.
ArrayIndexOutOfBoundsException: array index out-of-bounds exception
Cause: access to an index that does not exist
NullPointerException: NULL pointer exception
Cause: the value of the array name is null and does not point to the address value. You also use the array name to access its elements.
Array attribute: length, used to obtain the length of an array.
Format: array name. length