Java memory allocation and java allocation

Source: Internet
Author: User

Java memory allocation and java allocation

Java programs allocate different spaces for data to improve program efficiency:

The specific division is as follows:

1. STACK: stores local variables.

2. Heap: stores all new things.

3. Method Area:

4. Local Method Area: (related to the system)

5. registers: (CPU usage)

 

Local variables: variables in the method definition or method declaration are called local variables.

 

Heap memory features:

1. Each new item has an address value.

2. Each variable has a default value.

Byte, short, int, long is 0

Float, double is 0.0

Char "\ u0000" is equivalent to null

The reference type is null.

3. After use, it turns into garbage, but it is not recycled immediately. It will be recycled when the garbage collector is idle.

Stack memory features:

Data is released when it leaves the scope.

 

The value of the array name is the address, and the value of the array element (that is, the value of the array name [Index]) is the value of the data stored in the array.

 

Int [] arr3 = arr; // This is to give the arr address to arr3, and now the first address of arr is the same as that of arr3.

 

ArrayIndexOutOfBoundsException: array index out-of-bounds exception

Cause: access to an index that does not exist

NullPointerException: NULL pointer exception

Cause: the value of the array name is null and does not point to the address value. You also use the array name to access its elements.

 

Array attribute: length, used to obtain the length of an array.

Format: array name. length

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.