- Single Instance
- Global Access
- Lazy or Eager InitialisationĀ Support creating the instance either when needed (lazy) or when the class is loaded (eager).
- Thread Safety
- Private Constructor
/*package whatever //do not write package name here */
import java.io.*;
class Singleton {
// static class
private static Singleton instance;
private Singleton()
{
System.out.println("Singleton is Instantiated.");
}
public static Singleton getInstance()
{
if (instance == null)
instance = new Singleton();
return instance;
}
public static void doSomething()
{
System.out.println("Somethong is Done.");
}
}