| 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: 4761
|
|
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?
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3056
|
|
|
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: 3056
|
|
|
Actually, you're right. I missed the public constructor in Toolkit. It's not singleton.
|
 |
 |
|
|
subject: Singleton design pattern in core java
|
|
|