Hi
This question ask me in a interview i have dont idea about it.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
MuthuMari MPosted May 2, 2012, 1:13 PM
singleton pattern must satisfy the single instance and global access .
Java has several design patterns Singleton Pattern being the most commonly used. Java Singleton pattern belongs to the family of design patterns, that govern the instantiation process. This design pattern proposes that at any time there can only be one instance of a singleton (object) created by the JVM.
pls refer this url
http://www.javabeginner.com/learn-java/java-singleton-design-pattern
thanks.
If this post is useful then mark it as "Accepted Answer"
Satyapriya NayakPosted May 2, 2012, 1:01 PM
Singleton pattern used when we want to allow only a single instance of a class can be created inside our application. Using this pattern ensures that a class only have a single instance by protecting the class creation process, by setting the class constructor into private access modifier.
To get the class instance, the singleton class can provide a method for example a getInstance() method, this will be the only method that can be accessed to get the instance.
There are some rules that need to be followed when we want to implement a singleton.
clone()method of thejava.lang.Objectclass and throwCloneNotSupportedExceptionso that another instance cannot be created by cloning the singleton object.And this is how we use the
Servicesingleton class.Please refer the below links
http://radio-weblogs.com/0122027/stories/2003/10/20/implementingTheSingletonPatternInJava.html
http://www.kodejava.org/examples/12.html
Thanks
VulpesPosted May 2, 2012, 12:53 PM
Check out this thread:
http://stackoverflow.com/questions/70689/efficient-way-to-implement-singleton-pattern-in-java