Why the Java member variable can be uninitialized and the local variable must be initialized

Source: Internet
Author: User

For Java Virtual machine memory This is always a bit of a mystery, and today, the deep understanding of the JVM virtual machine to turn over, the rationale for the Java memory area.

The AVA virtual machine stack describes the memory model that the Java method executes: Each method creates a stack frame to hold local variable tables, operand stacks, dynamic links, method exits, and so on. The amount of memory space required for a local variable table is allocated during compilation, and when entering a method, this method requires that the local variable space allocated on the stack frame is fully deterministic and does not change the size of the local variable table while the method is running. This means that local variables must be initialized at the time of creation to determine the allocated memory size.

The Java heap holds an instance of all objects, and almost all object instances allocate memory here. In a hotspot virtual machine, after the memory is allocated, the virtual machine needs to initialize the allocated memory space to a value of 0. This step ensures that an instance field of an object can be used directly in Java code without assigning an initial value, and the 0 value corresponding to the data type of those fields that the program can access.

Why the Java member variable can be uninitialized and the local variable must be initialized

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.