This example shows creating a simple singleton. Singletons provides a mechanism to
have a single instance of a class throughout the life cycle of the Application.
It ensures a class has only one instance and provides a global point of access to it.
/**
* Pre-initialized singleton.
*/ private static final Singleton instance = new Singleton();
/**
* Make sure to have private default constructor.
* This avoids direct instantiation of class using
* new keyword/Class.newInstance() method
*/ private Singleton() {
init();
}
private void init() {
//Initialization code
}
public static Singleton getInstance() { return instance;
}
}