Home  >  Article  >  Java  >  What content is stored in the stack, heap, and method area respectively?

What content is stored in the stack, heap, and method area respectively?

王林
王林forward
2020-06-24 16:34:2813431browse

The stack stores values ​​and objects of basic data types as well as references to basic data; all objects stored in the heap are objects, and each object contains information about a corresponding class; the method area is used by all threads Shared, the method area contains all class and static variables.

What content is stored in the stack, heap, and method area respectively?

(Recommended tutorial: Getting started with java development)

Heap area:

1. Storage All are objects, and each object contains information about a corresponding class. (The purpose of class is to get operation instructions)

2. JVM has only one heap area (heap) shared by all threads. Basic types and object references are not stored in the heap, only the object itself is stored.

Stack area:

1. Each thread contains a stack area. The stack only stores values ​​and objects of basic data types and references to basic data.

2. Each thread The data in each stack (basic data types and object references) are private and cannot be accessed by other stacks.

3. The stack is divided into 3 parts: basic type variable area, execution environment context, and operation instruction area (storage operation instructions).

Method area:

1. Also called the static area, like the heap, it is shared by all threads. The method area contains all class and static variables.

2. The method area contains elements that are always unique in the entire program, such as class and static variables.

(Video tutorial recommendation: java video tutorial)

The above is the detailed content of What content is stored in the stack, heap, and method area respectively?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete