wood burning stoves*
The moose likes Beginning Java and the fly likes wat is singletone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "wat is singletone" Watch "wat is singletone" New topic
Author

wat is singletone

anilellendula kumar
Ranch Hand

Joined: Jul 12, 2005
Posts: 43
Hai!

Wat is singletone pattern, can anybody help me with an one example,how to make class as a singletone
Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129
In Singleton Pattern, You can't create a object for others class. They are restricted by making the constructor of their as private.


For the Singleton class the following is Mandatory:
1. Constructor should be private.
2. The object should be static.
(i.e., static classname ref = new classname(); )
3. Use static method to get the instance.


May be this link will be useful http://www.coderanch.com/t/400320/java/java/Singleton
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
"Mandatory" is a bit strong there. Singleton has a mechanism to control the number of instances of a class. The number is usually "one" but there could be cases where some other small, controlled number is appropriate. And there are other mechanisms to control creation besides a private constructor.

The simplest mechanism is as described above:


Do look up the other threads on this topic. We've discussed WHY you'd want a singleton and some of the dangers many times before.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Have you ever heard of Google? If not, check out all the links it gives that describe the Singleton pattern.

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: wat is singletone
 
Similar Threads
Singletone Pattern
singletone pattern
singletone ServiceLocator
how to create a singletone class
Data: Mutition/Singletone