memory allocation in Java

Source: Internet
Author: User

Java memory allocation, mainly divided into 4 blocks!
A piece is used to put code, that is, to compile something.
A piece is used to install static variables, such as variables with the static keyword, such as String constants.
A stack, or stack, is used to load variables and reference types! But the difference is that after the variable is loaded, there is a value on the variable, and the reference type itself has no value on the stack.
A heap, that is, heaps! Heap can be summed up in a word, loaded new things!

So in summary, the basic data types are all in the stack, and the reference type, the variable is placed in the stack, the real content is placed in the heap, that is, when new a reference type, he will be placed in the heap, and the reference type variable in the stack will point to the heap of your new out of the thing!
Two types of data:

1) Basic Data type
Integer type (byte/short/int/long)
Floating-point type (float/double)
Character type (char)
Boolean Type (Boolean)
2) Reference type: Class/interface/array
Also attached are 2 points notes:
1. Two ways to initialize a Java array:
Static (given element) and dynamic (given length)
Static characteristics of 2.java arrays:
After the Java Array (object) is initialized, the array length is immutable, and the array object is a space for the memory allocation when the array is created;

Initialize: Allocates memory space for an array element and assigns an initial value to each element;

memory allocation in Java

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.