title: Why attempt to print uninitialized variable does not always result in an error message
body: <p>Some may find it similar to the SO question <a href="https://stackoverflow.com/questions/24990691/will-java-final-variables-have-default-values?lq=1">Will Java Final variables have  default values?</a> but that answer doesn't completely solve this, as that question doesn't directly print the value of x within instance initializer block. </p>
  
  <p>The problem arises when I try to print x directly inside the instance initializer block, while having assigned a value to x before the end of the block :</p>
  
  <h2>Case 1</h2>
  
  <pre><code>class HelloWorld {
  
      final int x;
  
      {
          System.out.println(x);
          x = 7;
          System.out.println(x);    
      }
  
      HelloWorld() {
          System.out.println("hi");
      }
  
      public static void main(String[] args) {
          HelloWorld t = new HelloWorld();
      }
  }
  </code></pre>
  
  <p>This gives a compile time error stating that variable x might not have been initialized.</p>
  
  <pre><code>$ javac HelloWorld.java
  HelloWorld.java:6: error: variable x might not have been initialized
          System.out.println(x);
                             ^
  1 error
  </code></pre>
  
  <h2>Case 2</h2>
  
  <p>Instead of directly printing, I am calling a function to print:</p>
  
  <pre><code>class HelloWorld {
  
      final int x;
  
      {
          printX();
          x = 7;
          printX();
      }
  
      HelloWorld() {
          System.out.println("hi");
      }
  
      void printX() {
          System.out.println(x);
      }
  
      public static void main(String[] args) {
          HelloWorld t = new HelloWorld();
      }
  }
  </code></pre>
  
  <p>This compiles correctly and gives output</p>
  
  <pre><code>0
  7
  hi
  </code></pre>
  
  <p>What is the conceptual difference between the two cases?</p>