What does a Singleton class do?

Hello All,
I would like to know what functioanlity can be achieved using Singleton classes?It was an interview question.
can Anyone help me explaining from the basic about a Singleton class?
Thanks in advance,
Vijay

A singleton class only has one instance. I've used it once for databas connection pooling. Permitting only one instance of a class may sometimes be desirable, there isn't any magic about it.
This is a singleton class:
public class MySingleton
    private static MySingleton instance;
    private MySingleton() {}
    public static getInstance()
        if (instance == null) instance = new MySingleton();
        return instance;
}

Similar Messages

  • What does the SomeClassIdentifier.class keyword do?

    I see this often.
    SomeClassIdentifier.class == SomeClassIdentifier.getClass() ?

    I see this often.
    SomeClassIdentifier.class == SomeClassIdentifier.getClass() ?Not quite; the getClass() method is a non-static method inherited from the Object class.
    It returns a Class object representing the runtime class of the object for which the method was
    invoked. The funny .class notation is a class literal, it also evaluates to a Class object, but
    this object will represent the type that was mentioned on the left of the dot. e.g. -- Object a= new String("foo");
    String  b= new String("bar"); both a.getClass() and b.getClass() will return a Class object for the String class.
    String.class will evaluate to that same object, but Object.class wouldn't of course ...
    You can even create class literals for primitive types or arrays of even for void.
    kind regars,
    Jos

  • I keep getting this error message: ITunes was unable to load data class information from Synch Services. Reconnect or try again later. What does that mean? Can I fix it? or do I have to wait for the next update?

    I keep getting this error message: ITunes was unable to load data class information from Synch Services. Reconnect or try again later. What does that mean? Can I fix it? or do I have to wait for the next update?

    See TS2690: iTunes for Windows: "Unable to load data class" or "Unable to load provider data" sync services alert.
    tt2

  • I'm trying to sync my i phone. I haven't synced it in a few months, but the notice that comes up is  itunes was unable to load data class information from sync services..what does it mean?

    I'm trying to sync my i phone. I haven't synced it in a few months, but the notice that comes up is  itunes was unable to load data class information from sync services..what does it mean?

    In the course of your troubleshooting to date, have you worked through the following document?
    iTunes for Windows: "Unable to load data class" or "Unable to load provider data" sync services alert

  • What does $ sign in a class name signifies

    I have downloaded a project as a jar file(zip), when I unzipped it it gave me two files
    SchoolQadBase.java( Which has Class defn and methods)
    SchoolQadBase$RecordType.java(this has a Record type defined it).
    What does the $ sign in the class name signifies?
    Can I just include the RecordType in my SchoolQadBase.java and delete the other file?
    If I rebuilt the project does that affect any of my functionality.
    SchoolQadBase$RecordType.java
    public enum RecordType
      CUSTOMER, END_USER, SHIP_TO, SALES_ORDER;
      private String value;
      public String getValue()
        return this.value;
    My Java class SchoolQadBase.java
    package org.atcc.erpproxy.model;
    import java.io.Serializable;
    import java.util.Date;
    public class ErpQADBase extends AbstractErpObject
      implements Serializable
       private String rollNumber = "";
       private String department1 = "";
      private String department2 = "";
      private String room = "";
       private RecordType recordType;
    public RecordType getRecordType() {
        return this.recordType;
      public void setRecordType(RecordType recordType) {
        this.recordType = recordType;
    }

    What does the $ sign in the class name signifies?It signifies that it is an inner class
    Can I just include the RecordType in my SchoolQadBase.java and delete the other file?Definitely not
    Edited by: tjacobs01 on Nov 17, 2008 7:46 PM

  • Registering class - what does it mean?

    In one book dealing with JDBC there's statement like: "Whenever a driver is loaded into memory
    Class.forName("org.gjt.mm.mysql.Driver")
    it is registered as an available driver with the
    java.sql.DriverManager
    class".
    I have to say that I'm not newbie in database/JDBC programming and that I already created dozens of programs and web applications working with databases using DriverManager/DataSource approaches but now I'd like to understand what's really going on in the background with driver class.
    When you say "driver is registered" what does it really mean; what is registered and where?, how it is registered?, is it registered somewhere as ActiveX/COM component in Windows registry?

    hi sbrbot,
    There has been lot of confusion in people who try to get deep into what the books are telling. let me tell you what i could understand from analysing the informations and specifications ....
    when u call Class.forName with the driver class as the argument.., u instantiate a class of the driver.. like org.gjit.mm.mysql.Driver.. This class will contain some mechanism.., usually a static method that will call the java.sql.DriverManager.registerDriver(DriverClass) method.. this method needs the driver class as argument.. u can see it in the java sdk source code..
    The DriverManager now gets a handle to the driver class instance and whatit does can be seen from the foll. code ..in the java.sql.DriverManager class...
        public static synchronized void registerDriver(java.sql.Driver driver)
         throws SQLException {
         if (!initialized) {
             initialize();
         DriverInfo di = new DriverInfo();
         di.driver = driver;
         di.driverClass = driver.getClass();
         di.driverClassName = di.driverClass.getName();
         drivers.addElement(di);
         println("registerDriver: " + di);
        }for your information.. if u are again doubtful abt something.. see the foll. code part tooo again from java.sql.DriverManager
    // DriverInfo is a package-private support class.
    class DriverInfo {
        Driver         driver;
        Class          driverClass;
        String         driverClassName;
        public String toString() {
         return ("driver[className=" + driverClassName + "," + driver + "]");
        }So i hope u now know how the DriverManager class stores the information about the drivers that are available.. :-D
    Hope that was of some help.. do correct me if my concepts are wrong.
    cheers,
    -Jer

  • What does it mean by Stream and how does it is different from Class?

    What does it mean by Stream and how does it is different from Class?

    www.dictionary.com does
    Stream: An abstraction referring to any flow of data from a source (or sender, producer) to a single sink (or
    receiver, consumer).
    Class:
    The prototype for an object in an
    object-oriented language; analogous to a derived type in a
    procedural language. A class may also be considered to be a
    set of objects which share a common structure and behaviour.
    The structure of a class is determined by the class
    variables which represent the state of an object of that
    class and the behaviour is given by a set of methods
    associated with the class.

  • What does the class CL_EXITHANDLER do ? What the significance of this class

    what does the class CL_EXITHANDLER do ? What the significance of this class,

    Peters,
    Welcome to SDN!
    you can see this class in SE24 and than choose GET INSTENCE method DB on it. than put break-point on
    CALL METHODcl_exithandler=>get_class_name_by_interface
    finally run any t-code you will come into debugger mode and if you see in exit_name value after pressing F6 you will get BADi name of this perticuler T-code.
    basically we use this class for findings BADi.
    Amit.

  • What does a $ sign mean in a class name

    What does a $ sign mean in a class name? like java/util/HashMap$Entry

    What does a $ sign mean in a class name? like
    java/util/HashMap$EntryIt means it's an inner class.

  • Java1.5: Class AbstractCollection E E - what does it mean?

    Class AbstractCollection<E> <E> - what does it mean?
    http://java.sun.com/j2se/1.5.0/docs...Collection.html
    I also found <T> symbol e.g. Interface Iterable<T>
    http://java.sun.com/j2se/1.5.0/docs...g/Iterable.html
    ????

    http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html
    http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

  • When clicking on opening mail or any page a pop up says: Components.classes['@Softage.r4/Skype/SkypeFffExtension'] is undefined. What does it mean and how can I fix it?

    When I open up Mozilla or try to open up mail or website, I have to click okay each time I try to read something because it tells me: Components.classes['@Softage.r4/Skype/SkypeFfExtension',] is undefined.
    What does this mean and how can I clear up the problem?
    Thank you,
    Melinda

    Make sure Thunderbird isn't blocked by a personal firewall.

  • What does Apple class as a "high quality" download from iTunes (music)?

    What does Apple class as a "high quality" download from iTunes (music)?

    no1villafan wrote:
    Not really high quality, then?
    I guess that depends on how you define "high quality," eh?
    But seriously, in blind listening tests the vast majority of people can not tell the difference between AAC @ 256 Kbps and a CD. So it can be argued that the tracks available on the iTunes Store are, at least, CD quality. And since the tracks Apple gets to sell are coming directly from the master recordings it could also be argued they are, in some cases, better than CD quality.
    Just because a digital audio track is lossless does not automatically make it "high quality." At least, not to me.

  • What does MyClass.class.getClassLoader().getResource() do?

    Um. . .ok, I'm having a LD moment here. . .
    What does this java statement do?
    MyClass.class.getClassLoader().getResource("scripts").getPath() ;

    Here's the error from the log:
    java.lang.NullPointerException
         at com.oneok.dbLoader.scripts.OngDailyScriptLoader.getScripts(OngDailyScriptLoader.java:46)
         at com.oneok.dbLoader.scripts.OngDailyScriptLoader.Run(OngDailyScriptLoader.java:465)
         at com.oneok.dbLoader.scripts.OngDailyScriptLoader.run(OngDailyScriptLoader.java:494)
         at org.apache.jsp.runScript_jsp._jspService(runScript_jsp.java:52)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
         at java.lang.Thread.run(Unknown Source)

  • So i dropped my iphone 4 in class and the screen is cracked. it wont turn on so i went home and connected it into my itunes and the phone just keeps beeping like every ten seconds and the phone lights up just a little. What does this all mean?

    so i dropped my iphone 4 in class and the screen is cracked. it wont turn on so i went home and connected it into my itunes and the phone just keeps beeping like every ten seconds and the phone lights up just a little. What does this all mean?

    It means you should take it to the Genius Bar. You will no doubt need to buy an out of warranty replacement.

  • What is Singletone class?

    I would desire to apprehend the brief description about usage of Singletone class and where it can be applied.plz help me

    example
    public class Singleton {
    private static Singleton INSTANCE = null;
    // Private constructor suppresses
    // default public constructor
    private Singleton() {}
    //synchronized creator to defend against
    multi-threading issues
    //another if check here to avoid multiple
    instantiation
    private synchronized static void createInstance()
    if (INSTANCE == null) {
    INSTANCE = new Singleton();
    public static Singleton getInstance() {
    if (INSTANCE == null) createInstance();
    return INSTANCE;
    Thanks
    Siju Kurian
    Starmark service ltdDon't use this example in real applications, it has a serious flaw. Read http://java.sun.com/developer/technicalArticles/Programming/singletons/ .This example is implementation of Double-checked locking, which lacks proper synchronization.
    In almost all cases, solution provided by georgemc is applicable - it is simple and provides lazy initialization unless class have other non-private static methods/fields or non-private constructors (which may trigger initialization of class when used) (JLS, 12.4.1).

Maybe you are looking for

  • Change Page Size in PDF

    How do I change the size of every page in an existing PDF? I'm using Acrobat 9.

  • SQL Azure: More Intermittent Timeouts

    Hi guys, We have a set of 5 online auction systems running on Windows Azure & SQL Azure. Each system consists of a single web worker and one or more web roles. Each system is using ASP.NET MVC 3 and Entity Framework, Repository Pattern and StructureM

  • Acrobat 9.5 - I'm getting a 148:3 error.  Everything worked fine yesterday, nothing has changed Win7

    Today I tried to use Acrobat 9.5 and I am receiving this message:  "Licensing for this product has stopped working." "You cannot use this product at this time.  You must repair the problem by uninstalling and then reinstalling this product of contact

  • I can't found my Apple ID page

    I make a id &password bt bt I don't know where I receive my email verification I try many time bt not found plz help me

  • Losting the Control Reference

    I have a jpf and web service using a Tuxedo control. In some situations, the reference to var of the tuxedo control is set tu null in the JPF . The reference to the same control in the WS is working OK. Any help will be welcome