title: Will Java Final variables have default values?
body: <p>I have a program like this:</p>
  
  <pre><code>class Test {
  
      final int x;
  
      {
          printX();
      }
  
      Test() {
          System.out.println("const called");
      }
  
      void printX() {
          System.out.println("Here x is " + x);
      }
  
      public static void main(String[] args) {
          Test t = new Test();
      }
  
  }
  </code></pre>
  
  <p>If I try to execute it, i am getting compiler error as : <code>variable x might not have been initialized</code> based on java default values i should get the below output right??</p>
  
  <pre><code>"Here x is 0".
  </code></pre>
  
  <p>Will final variables have dafault values?</p>
  
  <p>if I change my code like this,</p>
  
  <pre><code>class Test {
  
      final int x;
  
      {
          printX();
          x = 7;
          printX();
      }
  
      Test() {
          System.out.println("const called");
      }
  
      void printX() {
          System.out.println("Here x is " + x);
      }
  
      public static void main(String[] args) {
          Test t = new Test();
      }
  
  }
  </code></pre>
  
  <p>I am getting output as:</p>
  
  <pre><code>Here x is 0                                                                                      
  Here x is 7                                                                                     
  const called
  </code></pre>
  
  <p>Can anyone please explain this behavior..</p>