Java Basics (bottom)

Source: Internet
Author: User

1. Overloading of methods (overload)

Concept: In the same class, more than one method of the same name is allowed, as long as their number of arguments or parameter types or parameter order are different.

Reason for existence: the difference in the same class of methods that masked an object is caused by different parameters.

Features: independent of the return value type, regardless of the parameter name, see only the parameter list.

Rule: Two identical, one different: the same method name in the same class; The parameter list is different: (Number of arguments, type of parameter, parameter order).

2. Arrays

Concept: A collection of data of the same type;

The benefits of arrays: Each element in the array is numbered, numbering starts at 0, and increments to facilitate manipulation of these elements;

Using a Java array: You must declare the array before allocating memory to the array;

How one-dimensional arrays are declared: type varname[]; or type[] varName; (recommended)

When the Java language declares an array, it cannot specify its length (number of elements) int a[5]; Illegal

An array in Java must be initialized before it can be used, the so-called initialization is to allocate memory for array elements of arrays and assign values to each array element;

There are two ways to initialize an array:

Static initialization: The initial value of each array element is specified by us at initialization, and the desired array length is determined by the system;

Format: Array name = new array type []{element 1, Element 2, Element 3 ... Element n}; Simplified Syntax: array name = {element 1, element 2, Element 3 ... Element n};

Dynamic initialization: The length of the array specified by us when initializing, and the initial value assigned by the system array element;

Format: Array name = new array type [array length];

  cannot be used in conjunction with static and dynamic initialization: that is, the length and elements of the array cannot be specified at the same time;

once the length of the array is determined, it cannot be changed, and the array is fixed length;


3. Array manipulation Common errors

Array pin out of bounds exception (arrayindexoutofboundsexception)

Null reference exception (NullPointerException)

4. Memory Features

Different memory space is opened up in order to have a different way of processing the data in each piece of memory, improve the efficiency.

Stack memory features: Store local variables and automatically free memory when space is not used.

Heap memory Features: storage arrays and objects, entities created with the new keyword are stored in heap memory. An entity has a memory address value. The variables in the heap memory have default initialization values. Garbage collection mechanism, Java-specific memory management mechanism, in an unscheduled time to remove the garbage to free space.

Java Basics (bottom)

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.