File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes what are singleton classes in Java API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what are singleton classes in Java API" Watch "what are singleton classes in Java API" New topic

what are singleton classes in Java API

sirisha makkapati
Ranch Hand

Joined: Dec 10, 2006
Posts: 83
Any one Please Tell me

what are singleton classes in Java API

Guru dhaasan
Ranch Hand

Joined: Sep 13, 2006
Posts: 126

basically singleton class allows only one instance of the class to be created at any time

Thanks, Shiv
SCJP, OCE - JSP & Servlets Developer
David McCombs
Ranch Hand

Joined: Oct 17, 2006
Posts: 212
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?

"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

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

I agree. Here's the link:
subject: what are singleton classes in Java API
It's not a secret anymore!