public class Singleton{
/**
* Private constructor
*/
private Singleton(){
}
/**
* private static class, which only gets loaded when method getInstance() is invoked.
*/
private static class SingletonHolder{
/**
* In this class initialize statically the instance of the Singleton Class.
*/
public final static Singleton instance=new Singleton();
}
/**
* The actual singleton getInstance method.
* Only when you call this method the first time
* the inner static class SingletonHolder gets initialized
* Hence this is singleton
*/
public static Singleton getInstance(){
return SingletonHolder.instance;
}
}
Just my 50 cents!!
Rohit