title: Default values and initialization in Java
body: <p>Based on <a href="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html" rel="noreferrer">my reference</a>, primitive types have default values and Objects are null. I tested a piece of code.</p>
  <pre><code>public class Main {
      public static void main(String[] args) {
          int a;
          System.out.println(a);
      }
  }
  </code></pre>
  <p>The line <code>System.out.println(a);</code> will be an error pointing at the variable <code>a</code> that says <code>variable a might not have been initialized</code> whereas in the given reference, <code>integer</code> will have <code>0</code> as a default value. However, with the given code below, it will actually print <code>0</code>.</p>
  <pre><code>public class Main {
      static int a;
      public static void main(String[] args) {
          System.out.println(a);
      }
  }
  </code></pre>
  <p>What could possibly go wrong with the first code? Do class variables behave different from local variables?</p>