"Basic Java Tutorial"-on arrays and their memory control

Source: Internet
Author: User

We all know before using Java data that we have to initialize the array object first. When all elements of an array are allocated the appropriate memory space, when the initial value is set, the array initialization is complete. The program will not be able to re-alter the position and size of the array object in memory. So:

The 1.JAVA array is static, that is, once initialized, its length is immutable.

2. An array variable is a reference variable, not an array object itself.

3. Two ways of initializing:

Dynamic initialization: Specifies the length of the array, and the initial value is automatically generated.

Static initialization: Specifies the initial value, and the length is automatically generated.

4. In Java, the reference variable itself does not have to be initialized, and the object referenced by the reference variable needs to be initialized.

5. All local variables (basic type variables, reference type variables) are stored in the stack memory of the method, and the actual objects (array objects, Java objects) referenced by the reference variable are deposited in the heap memory.

= "Reference variable is not necessarily stored in stack memory, eg,3 dimension array

* Easy to confuse: When does a reference variable refer to its own province, and when does it refer to its referenced object in heap memory?

does not call its method or property, refers to itself, and vice versa, refers to the object it references in heap memory


6. Primitive type array: Each element is a value type (base type)

Array of reference types: Each element is also a reference type, and you need to point to the actual object

7. Java only allows access to array objects in heap memory by reference variables and does not allow direct access to array objects in heap memory

8. Multidimensional arrays are initialized by a one-dimensional array, initialized from the leftmost end, and each element is further initialized by reference type.

eg


Int[][] A;

A = new int[4][];

A[0] = new INT[2];


PS: If there is any problem in the Java group: 457036818 put forward or direct message

This article is from the Java Learning Video tutorial blog, so be sure to keep this source http://10239772.blog.51cto.com/10229772/1658487

"Basic Java Tutorial"-on arrays and their memory control

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.