title: Static fields in JVM loading
body: <p>As part of JVM Loading, Linking and Initalizing, When the</p>
  
  <ol>
  <li>static fields</li>
  <li>final static fields</li>
  </ol>
  
  <p>in Class </p>
  
  <ol>
  <li>allocating in memory</li>
  <li>init as default value</li>
  <li>init as real value</li>
  </ol>
  
  <p>In the case of the static final variables, I think that everything happens in the Loading step, because all values are already in Constant Pool.</p>
  
  <p>But I can not figure out what's going on with the static fields. In principle, in the written <a href="https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-5.html#jvms-5.4.2" rel="nofollow noreferrer">documantation</a> that they are initialized with default value in the Preparation step.</p>
  
  <blockquote>
    <p>Preparation involves creating the static fields for a class or interface and initializing such fields to their default values (§2.3, §2.4). This does not require the execution of any Java Virtual Machine code; explicit initializers for static fields are executed as part of initialization (§5.5), not preparation. </p>
  </blockquote>
  
  <p>But in this <a href="http://www.artima.com/insidejvm/ed2/jvm5.html" rel="nofollow noreferrer">source</a> (Class Variables paragraph) loading the static fields initialization occurs already in the Loading step. This makes sense because at the end of the loading step an instance of the class object is created, and it must contain room for the static fields.</p>
  
  <blockquote>
    <p>Before a Java virtual machine uses a class, it must allocate memory from the method area for each non-final class variable declared in the class. </p>
  </blockquote>
  
  <p>So I'd like to know what the right fact is in this case.</p>