Java BASICS (6) JavaSE and javase
1. Array
Concept: a collection of the same type of data. An array is actually a container.
Benefit: You can automatically number the elements in the array from 0 to facilitate operations on these elements.
Format:
① Element type [] array name = new element type [number of elements or array length]; example: int [] arr = new int [5];
②. Element type [] array name = new element type [] {element, element ,....}; example: int [] arr = new int [] {,}; or int [] arr = };
Common exceptions:
①. ArrayIndexOutOfBoundsException: // This exception occurs when you access an index that does not exist in the array.
②. NullPointerException: // when the referenced variable does not point to any object, it is still using it to operate the object. This exception occurs.
③. [I @ c17164 // hash address. @ indicates an integer array.
Appendix 1: Memory Division:
1. Register.
2. Local method area. (Related to the system)
3. Method area.
4. stack memory.
All local variables are stored, and once the scope of the variable ends, the variable is automatically released.
5. heap memory.
Storage is an array and an object (in fact, an array is an object). Every new object is created in the heap.
Features:
1. Each object has a first address value.
2. Each variable in the heap memory has a default initialization value, which varies depending on the type. The integer is 0, the decimal point is 0.0 or 0.0f, boolean false, char '\ u0000 '.
3. Garbage collection mechanism.