title: Why is it mandatory to have private Constructor inside a Singleton class
body: <p>This is my singleton class for obtaining the database connection.</p>
  
  <p>I have a question here: why it compulsory to have a private constructor inside a singleton class (as throughout my entire application I am calling this class only once) and as one instance of a class can be achieved using the static method?</p>
  
  <p>Can this private constructor can be avoided, or is it mantadatory?</p>
  
  <pre><code> public class ConnPoolFactory {
          private static DataSource dataSource;
          private static Connection connection;
  
          private ConnPoolFactory() {
              System.out.println(" ConnPoolFactory cons is called ");
          }
  
          public static synchronized Connection getConnection() throws SQLException {
  
              try {
  
                  if (connection == null) {
                      Context initContext = new InitialContext();
                      Context envContext = (Context) initContext
                              .lookup("java:/comp/env");
                      dataSource = (DataSource) envContext.lookup("jdbc/Naresh");
                      connection = dataSource.getConnection();
                  } else {
                      return connection;
                  }
  
              } catch (NamingException e) {
                  e.printStackTrace();
              }
  
              return connection;
  
          }
      }
  </code></pre>