Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what are singleton classes in Java API

 
sirisha makkapati
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any one Please Tell me

what are singleton classes in Java API

Thanks
Sirisha
 
Guru dhaasan
Ranch Hand
Posts: 126
Java Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
basically singleton class allows only one instance of the class to be created at any time
 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you asking what a singleton is or what classes in the API implement that pattern?

If the former, a search on this site should prove useful as it is a often talked about topic.

If the latter, look for a class with a private constructor AND has a static method named something like getInstance() or getNameOfClass. If a constructor is not shown in the API it is private.

A well known singleton is Runtime, but there are many more. Another possibility is MessageDigest. Although that one has a protected constructor, so I am not sure it can be considered a singleton. Anyone know?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Gurudhaasan",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted, often without warning

thanks,
Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic