Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Which classes are candidates of Singleton? Which kind of class do you make Singleton in Java?

user-image
Question added by Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
Date Posted: 2014/04/23
Mudassar Hakim
by Mudassar Hakim , Requirement Analyst & Software Developer , L&T Infotech

Candidates for singleton will be those classes which can be instantiated only once no matter how many times you call the instantiation process so that later when called again it return created instance rather than the a new instance.

Examples of Singleton classes could be your database connection object,, Principal object which is used for security

The decision for making a particular class as singleton is a design/architectural decision (and hence the name 'Singleton design pattern'). Most of the cases you make a class singleton becuase in the whole of the application (the JVM) you need a single source of information of a particular sort; or it could be that only one object can exist theoretically.

Yassine Sabi
by Yassine Sabi , Software Engineer , Capgemini

Most of the time, I use Singleton when it comes to sessions it needs to be instancied only once so every user has it's own session. 

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.