This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
You are right in saying that a singleton class allows only one instance of that class. But it is important to know that ONE INSTANCE PER JVM. That is to say that as long as the JVM is up and running, only one instance can be used. This is used when a Class is Behavior based rather than State based.
Thanks folks for your insights on Singleton Class. But I have a query. Shouldn't we override the clone method which every class inherits from the Object class in Java, to prevent any cloning of the object of our Singleton class.
In Singletons also make sure that the class can not be serialized.
Once serialized another instance can very well be created.
Probably make variable " singleton " as transient to prevent it from Serializing.
Do not implement java.io.Serializable.