GeeCON Prague 2014*
The moose likes Java in General and the fly likes Singleton design pattern in core java 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 design pattern in core java" Watch "Singleton design pattern in core java" New topic
Author

Singleton design pattern in core java

Praveen Kumar
Ranch Hand

Joined: Nov 06, 2006
Posts: 133
Hi,


Today I have been asked some examples of singleton design patterns in core java. But I could not able to get any examples. Please tell me if you know anything :-)
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7898
    
  21

Praveen Kumar wrote:Today I have been asked some examples of singleton design patterns in core java. But I could not able to get any examples. Please tell me if you know anything :-)

I presume you mean classes, not patterns.

The only one that springs readily to my mind is Runtime (java.lang.Runtime).

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  16

Not sure if the logging framework is included, but java.util.logging.LogManager is a singleton, I believe, and java.util.logging.Logger is instance controlled. java.awt.Toolkit is also singleton. Those are the only examples I can think of right now.
Manuel Petermann
Ranch Hand

Joined: Jul 19, 2011
Posts: 175

java.awt.Toolkit is an abstract baseclass but it is most definitifely not a singleton.

Ok my fault. Its sort of a mingleton. I think you could argue about that too because a singleton or derivates must always return the same Object but you can change the returned Object of the Toolkit.getDefaultToolkit method.


Please correct my English.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  16

Actually, you're right. I missed the public constructor in Toolkit. It's not singleton.
 
GeeCON Prague 2014
 
subject: Singleton design pattern in core java