title: Confusion between Singleton and Static method Java
body: <p>Suppose I want to implement the class which will provide me <code>Connection</code> for database connectivity. I can implement the same thing with two different code snaps given below.  </p>
  
  <p><strong><em>Method 1:</em></strong></p>
  
  <pre><code>class DBConnection1 {
      private static DBConnection1 instance = new DBConnection1();
      private DBConnection1(){
  
      }
      public static DBConnection1 getInstance(){
          return instance; 
      }
      public Connection getConnection(){
          Connection connection = null;
          //do my stuff to init the connection
          return connection;
      }
  }
  </code></pre>
  
  <p><strong><em>Method 2:</em></strong></p>
  
  <pre><code>class DBConnection2 {
      public static Connection getConnection(){
          Connection connection = null;
          //do my stuff to init the connection
          return connection;
      }
  }
  </code></pre>
  
  <p>And Accessing the above methods like,</p>
  
  <pre><code>class TestConnection{
      public static void main(String[] args) {
          //using method 1
          Connection connection1 =  DBConnection1.getInstance().getConnection();
          //using method 1
          Connection connection2 =  DBConnection2.getConnection();
      }
  }
  </code></pre>
  
  <p>I have little doubt which is better and why? And what is difference over there?</p>