One, the Java array is static
Java is a typical static language, the Java array is also static, that is, when the array is initialized, the length of the array is immutable;
Second, What is the initialization of the array
Array initialization is the allocation of contiguous memory space to an array object in heap memory and an initial value for each array element.
three, array initialization way
There are two ways of doing this:
1. Static initialization: The programmer explicitly specifies the initial value of each array element, and the size of the array is determined by the system;
2, dynamic initialization: By the programmer to specify the size of the array, the system for each array elements to allocate the initial value;
four, array variables and array objects
Array variable:
An array variable is a reference variable type (essentially a pointer), created in the stack area (in Java, where all local variables are stored in the stack, regardless of the basic data type (int, short, Long, Byte, Boolean, char, float, etc.) variable, or reference type variable; Java in heap memory objects usually do not allow direct access, in order to access the object, only through the stack area reference object
If string[] books = new String[5], books are the array variables;
Array objects:
The array object is a " true array ", created in heap memory ;
For an array object of the base type, the data element value is stored directly in the allocated memory space, and for an array object of a complex type (such as String), the allocated memory space is also referenced, referencing (pointing to) Chang (Constant Pool) or other memory area objects;
such as string[] books = new string[5]; new String[5] is an array object;
The relationship between them:
The array variable, referencing (pointing to) the array object in the heap memory;
Summary:
so please always remember: the Java array variable is a reference-type variable that is not an array object itself and does not require initialization, so long as the array variable points to a valid array object in heap memory, the program can use the array variable, which is substituted by the object it references, The system automatically changes to access the corresponding array object in the heap memory.