title: Static final variable along with static initializer block
body: <p>I made a class that contains:</p>
  
  <ol>
  <li><code>static final</code> variable</li>
  <li><code>static</code> initializer block with a <code>System.out.println()</code> statement</li>
  </ol>
  
  <p>If I call the <code>static final</code> variable from another class, the <code>static</code> block does not execute.</p>
  
  <p>As far as I know, the <code>static</code> initializer block executes when the class is loaded in memory.</p>
  
  <p>In this case, what is happening at the memory level?</p>
  
  <p>Is the class not loading in memory? If not, where do other classes get the address of the <code>final static</code> variable?</p>
  
  <hr>
  
  <p><strong>Case 1:</strong> <code>static</code> block does NOT execute</p>
  
  <pre><code>class Test2 {
      static final int a = 20;
  
      static {
          System.out.println("one");
      }
  }
  </code></pre>
  
  <p><strong>Case 2:</strong> <code>static</code> block <em>does</em> execute</p>
  
  <pre><code>class Test2 {
      static final int a;
  
      static {
          a = 20;
          System.out.println("one");
      }
  }
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>class Test {
      public static void main(String[] args) {
          System.out.println(Test2.a);
      }
  }
  </code></pre>
  
  <ul>
  <li><p>Case 1:</p>
  
  <pre><code>20
  </code></pre></li>
  <li><p>Case 2:</p>
  
  <pre><code>one
  20
  </code></pre></li>
  </ul>
  
  <p>So what is happening at both levels?</p>