title: How to initialize a constant object field for a class in java
body: <p>I wonder what is the best way to initialize a constant field of complex object type for a class , which one has the most performance?</p>
  
  <p>1) Inline initialization</p>
  
  <pre><code>public class TopClass {
     private static final ComplexObject sdf = new ComplexObject();
              
     public TopClass (
     }
  }
  </code></pre>
  
  <p>2) Initializer methods</p>
  
  <pre><code>public class TopClass {
       private static final ComplexObject sdf = initializeComplexObject();
       private static ComplexObject initializeComplexObject(){
                  return sdf == null ? new ComplexObject() : sdf;
       }
       public TopClass (
       }
  }
  </code></pre>
  
  <p>3) Initialization in constructors ,
  4) Static initializer blocks
  or what other approach you suggest ...</p>
  
  <p>Does the sdf initializes every time the new TopClass class is creating?
  I want sdf field only initialize once in the application lifetime.</p>