File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Singleton Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Singleton Object" Watch "Singleton Object" New topic

Singleton Object


Joined: Apr 12, 2005
Posts: 13
What�s the difference between a singleton class and a static class?

If the answer is static class is one approach to make a class �Singleton� I have one doubt.

If the constructor is public I can create more than one instance then how does it work like a singleton?
Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
i think this is what you are looking for.

please go through it. that should solve most of your queries.

Joined: May 10, 2005
Posts: 4
Please go thou the following link for more details about design pattenrs
Edwin Keeton
Ranch Hand

Joined: Jul 10, 2002
Posts: 214

If you were trying to implement Singleton with a "static class" (meaning all members of the class are static), you would not use a public constructor. You would implement an unused private constructor so there would be no public default constructor. Ane while you were at it you would make the class final to prevent a subclass creating an instance.

I agree. Here's the link:
subject: Singleton Object
It's not a secret anymore!