title: java beginner: initializing class variables
body: <p>I've just read the <strong>SUN java code conventions</strong>; very nice document btw. And I've read this</p>
  
  <blockquote>
    <p>6.3
    Initialization: 
    Try to initialize local variables where they’re declared. The only reason not to initialize a
    variable where it’s declared is if the initial value depends on some computation occurring first.</p>
  </blockquote>
  
  <p>And I was wondering if <code>Class variables</code> are having same suggestion or not, for example I have:</p>
  
  <pre><code>public class NNmatrix {
  
      protected ArrayList&lt;ArrayList&lt;Double&gt;&gt; matrix;     // line 1
      public NNmatrix() {
          matrix = new ArrayList&lt;ArrayList&lt;Double&gt;&gt;();     // line 2
      }
      /**
       * 
       * @param otherMtrx
       */
      public NNmatrix(final ArrayList&lt;ArrayList&lt;Double&gt;&gt; otherMtrx) {
          final int rows = otherMtrx.size();
          matrix = new ArrayList&lt;ArrayList&lt;Double&gt;&gt;(rows);  // line3
          for (int i = 0; i &lt; rows; i++) {
              this.matrix.add(new ArrayList&lt;Double&gt;(otherMtrx.get(i)));
          }
      }
  }
  </code></pre>
  
  <p>EDITING CODE# If I would initialize the <code>variable</code> where it's declared (in class), I would <strong>remove</strong> "line 2" and <strong>leave</strong> "line 3" because performance issue# reserving (rows) in memory as you know. </p>
  
  <p>The question is: </p>
  
  <ol>
  <li>Is doing that a good practice or initialization matter only apply for local variables inside methods etc only?</li>
  <li>If it's fine, I want to know which will come first if I did the EDITING CODE# the initialization @ line 3 or initialization @ line 1 ?</li>
  </ol>