The reader notes the basic accomplishments of Java programmers (array and memory management), java programmers
1.1 array Initialization
1.1.1 The java array is static
After the java array is initialized, the memory space occupied by the array and the length of the array are immutable.
Arrays in java programs must be initialized before they can be used.
Two methods are available for Array initialization:
1) Static initialization: during initialization, the programmer displays the initial values of each array element, and the system determines the array length.
2) Dynamic initialization: during initialization, the programmer only specifies the length of the array, and the system assigns the initial value to the array element.
* Do not use both static and dynamic initialization methods.
The array variable of java is a reference type variable. The array variable is not the array itself, it just points to the array object in memory.
/**
The array length of the Dynamic Language javaScript can be dynamically changed.
**/
1.1.2 must the array be initialized?
The array object must be initialized, but for the array variable, it does not need to be initialized. As long as the array variable points to a valid array object, the program can use the array variable normally.
1.1.3 initialization of basic type Arrays
The program directly allocates memory space for the array, and then saves the value of the array element to the corresponding memory.
All local variables are saved in the memory of the consumer. no matter whether they are basic variables or referenced variables, they are stored in their respective method stack memory; however, the objects referenced by referenced variables (including arrays and common java objects) are always stored in heap memory.
The referenced variable is essentially a pointer, as long as the program accesses the attribute by referencing the variable. Or call a method by referencing a variable. The referenced variable will be replaced by the object it references.
1.1.4 initialize a reference type array
The array element of the reference type array is still of the reference type. Therefore, the array element is stored as a reference and points to another memory, this memory stores the objects (including arrays and java objects) caused by the referenced variable)
1.2 use Arrays
The java language does not allow direct access to the data in the heap memory, so it cannot directly access the array objects in the heap memory. It only uses the array to reference variables to access the array.
* The java language avoids direct access to the data in the heap memory to ensure the program is more robust. If the program directly accesses and modifies the data in the heap memory, the data integrity in the memory may be damaged, resulting in the program Crash.
1.2.1 The array element is a variable
After an array is initialized, multiple variables of the same type are defined.
1.2.2 no multi-dimensional array
Multi-dimensional arrays are actually arrays whose elements are still an array.