Java stores data in several places

Source: Internet
Author: User

1. Registers

This is the fastest storage area within the processor and cannot be directly controlled.

2. Stacks

In RAM, the stack pointer moves down to allocate new memory, and the stack pointer moves up to free memory. Storage speed is second only to memory.

When you create a program, the Java system must know the life cycle of all items stored in the stack so that the stack pointer moves up or down. typically used to hold object references, objects are not stored on the stack.

* Exceptions: Java primitive type, instead of creating a variable with new, create an "automatic" variable that is not a reference. This variable stores the value directly and places it on the stack. The base type stores the actual value, not the object's reference.

3. Heap

Used to store Java objects. The advantage is that the compiler does not need to know how long the stored data will survive in the heap, and when an object is needed, the storage allocation is automatically made in the heap.

4. Constant storage

Placed directly inside the program code.

5. Non-RAM storage

The data is completely out of the program and can exist if the program is not running. such as stream objects and persisted objects.

Java stores data in several places

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.