Java's memory allocation is mainly divided into 4 blocks!
One piece is used to install code, which is what is compiled.
One block is used to hold static variables, such as variables using the static keyword, such as string constants.
One piece is stack, which is the stack, which is used to hold variables and reference types! But the difference is that after the variable is installed, the variable has a value, but the reference type itself has no value on the stack.
One piece is heap, which is the heap! Heap can be summed up in one sentence, loaded with new things!
So to sum up, basic data types are all in the stack, while reference types and variables are placed in the stack, and things with real content are placed in the heap, that is, when new is a new reference type, it will be placed in the heap, and the reference type variable in the stack will point to the new thing you created in the heap!
Two data types:
1) Basic data type
Integer type (byte/short/int/long)
Floating point type (float/double)
Character type ( char)
Boolean type (boolean)
2) Reference type: class/interface/array
Also attached are 2 notes:
1. Two ways to initialize java arrays:
static (Given elements) and dynamic (given length)
2. Static characteristics of java arrays:
After the java array (object) is initialized, the length of the array is immutable; the array object is a space allocated in memory when the array is created. ;
Initialization: allocate memory space for array elements and specify an initial value for each element;
The above is the detailed content of A brief analysis of Java memory allocation. For more information, please follow other related articles on the PHP Chinese website!