title: Use of Initializers vs Constructors in Java
body: <p>So I've been brushing up on my Java skills as of late and have found a few bits of functionality that I didn't know about previously. Static and Instance Initializers are two such techniques.</p>
  
  <p>My question is when would one use an initializer instead of including the code in a constructor? I've thought of a couple obvious possibilities:</p>
  
  <ul>
  <li><p>static/instance initializers can be used to set the value of "final" static/instance variables whereas a constructor cannot</p></li>
  <li><p>static initializers can be used to set the value of any static variables in a class, which should be more efficient than having an "if (someStaticVar == null) // do stuff" block of code at the start of each constructor</p></li>
  </ul>
  
  <p>Both of these cases assume that the code required to set these variables is more complex than simply "var = value", as otherwise there wouldn't seem to be any reason to use an initializer instead of simply setting the value when declaring the variable.</p>
  
  <p>However, while these aren't trivial gains (especially the ability to set a final variable), it does seem that there are a rather limited number of situations in which an initializer should be used. </p>
  
  <p>One can certainly use an initializer for a lot of what is done in a constructor, but I don't really see the reason to do so. Even if all constructors for a class share a large amount of code, the use of a private initialize() function seems to make more sense to me than using an initializer because it doesn't lock you into having that code run when writing a new constructor.</p>
  
  <p>Am I missing something? Are there a number of other situations in which an initializer should be used? Or is it really just a rather limited tool to be used in very specific situations?</p>