Singleton pattern

The singleton pattern allows you to guarantee that a class has only one instance.

Usually it is used to access a shared resources like print spooler or for centralized management like windows manager. Be careful with your own singleton, it must be memory-leak free.

class LazySingleton{
    // dissallow create object via constructor 
    // from outside of the class
    private LazySingleton() {}
    ...

    private static LazySingleton instance = null;

    public static LazySingleton getInstance() {
        if(instance==null){
            instance = new LazySingleton();
        }
        return instance;
    }
}
// more Java singleton examples