No.1 array and memory control, no.1 Array Control

Source: Internet
Author: User

No.1 array and memory control, no.1 Array Control

1. Dynamic and StaticInitialization(Array); Initialization includes: ① allocating memory ② assigning initial values

  • From the perspective of a program (system), "dynamic" refers to the dynamic initial value of the system (Assign the default value first, and assign a value to the default value if any program is displayed later.) (The programmer specifies the length of the array); "static" means that the system does not assign the initial value (the system specifies the length), that is, the programmer displays the assigned initial value.
  • Programmer's point of view: animation-programmers only specify the length, not the initial value; static-programmers do not specify the length, specify the Initial Value
  • Eg:
    1 // dynamically initialize 2 int score [] = new int [3]; // here there is a default value of 4 // The array is dynamically assigned through a loop, and the odd value is 5 for (int I = 0; I <score. length; I ++) {6 score [I] = I * 2 + 1; // change the default value to 7} 8 9 // initialize 10 int score statically [] = {, 19 };

2. Local variables are stored in the respective method stack (main method: main stack), and objects referenced by reference type variables are stored in the heap memory.

3. differentiate when a reference type variable refers to a variable and when it refers to a referenced object.

  • Referencing a variable is essentially a pointer. As long as the program accesses the property or calls a method through it, the referenced variable will be replaced by the object it references.

4. the array element refers to the value stored by the array object.

  • An array element is a variable and can be used as a common variable.
  • Differences:The variables declared by the main method belong to local variables stored in the main method stack, but the array elements are saved in the heap memory as part of the array object, whether they are basic or referenced array elements

5. Without multi-dimensional arrays, the essence of multi-dimensional arrays is still one-dimensional arrays.

  • The so-called multi-dimensional, in fact, is the index group element is still an array (here the array can be an n-dimensional) of the 1-dimensional array
  • During initialization, You can first initialize the leftmost dimension.
  • Int [5] [] []: indicates a 5-dimensional array. Its array element is a two-dimensional array, that is, its array element is a reference variable pointing to a two-dimensional array object.

6. the array in Java is static, that is, once the initialization is complete, the length cannot be changed.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.