Loading
Singleton class

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  What is a Singleton class ?


Ans)

Single class is a class for which only one Instance will be created per JVM. Singleton
classes would have Private Constructors so that instances will not be created from other
classes. In general Singleton classes are used to hold the static data like Properties
or some Constants in memory.

One difficulty you may face with the Singleton classes is keeping them in SYNC among all
the JVMs in a clustered ENV, you have to have your own mechanism for accomplish this.
Or you could avoid using singleton classes by using some popular In-Memory cache APIs
such as EHCache, which give you the opportunity of using their built-in Distributed Cache
features for clustered ENV.

Here is the sample:

class PropertyManager {
    private static PropertyManager propManager;
    private PropertyManager()  {
    }

    public static PropertyManager getInstance()  {
        if (null == propManager) {
            propManager = new PropertyManager();
        }
        return propManager;
    }
}



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

Singleton class


Singleton class

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free