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