Heap memory vs. stack memory in Java

Source: Internet
Author: User

1. Stack memory is used to store some basic types of variables, arrays, and object references; heap memory is primarily used to store some objects.

2. Static variable: The variable is statically modified, and the instance variable is a non-static modified variable.

3. The difference between a static variable and an instance variable:

1) A static variable is initialized as the class loads, it can have only one in memory, and the JVM allocates memory only once, while instances of all classes share static variables that can be accessed directly through the class name.

2) The instance variable is as an instance, and each time an instance is created, an instance variable is generated, which is die with the instance.

4. Static method:

The static modification method is called a statically method and can be called directly through the class name. Because it already exists at the time of class loading, it does not depend on any instances, so the static method must be implemented and cannot be an abstract method.

Heap memory vs. stack memory 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.