Java memory allocation, mainly divided into 4 blocks!
A piece is used to put code, that is, to compile something.
A piece is used to install static variables, such as variables with the static keyword, such as String constants.
A stack, or stack, is used to load variables and reference types! But the difference is that after the variable is loaded, there is a value on the variable, and the reference type itself has no value on the stack.
A heap, that is, heaps! Heap can be summed up in a word, loaded new things!
So in summary, the basic data types are all in the stack, and the reference type, the variable is placed in the stack, the real content is placed in the heap, that is, when new a reference type, he will be placed in the heap, and the reference type variable in the stack will point to the heap of your new out of the thing!
Two types of data:
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 points notes:
1. Two ways to initialize a Java array:
Static (given element) and dynamic (given length)
Static characteristics of 2.java arrays:
After the Java Array (object) is initialized, the array length is immutable, and the array object is a space for the memory allocation when the array is created;
Initialize: Allocates memory space for an array element and assigns an initial value to each element;
memory allocation in Java