Singleton Class Example

suggest change

Java Singleton Pattern

To implement Singleton pattern, we have different approaches but all of them have following common concepts.

/**
 * Singleton class.
 */
public final class Singleton {

  /**
   * Private constructor so nobody can instantiate the class.
   */
  private Singleton() {}

  /**
   * Static to class instance of the class.
   */
  private static final Singleton INSTANCE = new Singleton();

  /**
   * To be called by user to obtain instance of the class.
   *
   * @return instance of the singleton.
   */
  public static Singleton getInstance() {
    return INSTANCE;
  }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents