Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singleton design pattern in core java

 
Praveen Kumar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stephan van Hulst
Bartender
Posts: 6337
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stephan van Hulst
Bartender
Posts: 6337
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, you're right. I missed the public constructor in Toolkit. It's not singleton.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic