title: When we should go for a Singleton class in Java?
body: <p>As per my thoughts, we should make a class as Singleton when we share the same object state across the application. In that case we want the user to to restrict from creating a new instance every time so that they could not maintain the multiple states. Agreed. But the same behavior can be acheved by by declaring the instance variables as static. To me it looks it will also serve the same purpose whether its <code>cacheobjectcontainer</code>, <code>logger</code> or <code>Classloader</code> class.</p>
  
  <p>Please help me to understand above concept where static instance variable will not solve the purpose and class needs to be declared Singleton?</p>
  
  <p><strong>Edited Part</strong></p>
  
  <p>Ok let me bring some more clarity . The pupose of singleton class is to keep only one instance of singleton class across jvm. Agreed. But i am trying to think of reasons why we want to keep only one instance. <strong>There can be two reasons:</strong></p>
  
  <p>1) Object might be expensive to create. So we just want to keep only one instance. Agreed in this scenario declaring instance variables as static does not solve any purpose.</p>
  
  <p>2) We want to share the same state of object across application. I was thinking this is the main purpose of declaring the class as singleton. But it can be achieved simply by declaring the instance variables as static.</p>
  
  <p>But looks like 1 is the main reason of delaring any class as static not reason 2 because it can be achieved with static variable also.</p>
  
  <p><strong>Is this correct?</strong></p>