Java language learning 4-variables and Arrays

Source: Internet
Author: User

First, let's review the Java variable types:

Instance variable: no static attribute is added to the class property and is stored in each class object instance. The system assigns a default value to it.

Class variable: the owner of the static class in the class attribute, and the classCodeIt is stored together and has nothing to do with the instance of the class.

Local variable: The variable declared in the method is stored in the user stack. The system does not provide the initial value for the variable and must display initialization. Otherwise, the value is uncertain.

Function parameters: no space is allocated when not called. Space is allocated only when combined with real parameters.

Array in Java

Arrays are generally used to store a group of variables of the same type. for basic types:

Int [] a1 = new int [10]; // declares an array of 10 elements consisting of int

Int [] [] matrix = new int [5] [3]; // defines a two-dimensional array

For arrays, elements should be of the same type, but different types of objects can be stored through objects:

Object [] Magic = new object [10];

Magic [0] = new classa ();

Magic [1] = new classb ();

Array copy function in the system class:

Public static void arraycopy (Object SRC, int srcpos, object DEST, int destpos, int length ){...}

It seems that the array in Java is not of great significance, and most functions can be implemented through arraylist.

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.