File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Private Constructors in j2se Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Private Constructors in j2se" Watch "Private Constructors in j2se" New topic
Author

Private Constructors in j2se

Pandu Rangam
Greenhorn

Joined: Dec 08, 2006
Posts: 24
Can any one tell is there any class with a private constructor in j2se api other than Math class?


SCJP 1.4,<br />SCWCD 1.4
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24057
    
  13

Sure, lots. java.lang.System and java.util.Arrays are the first two that come to mind.


[Jess in Action][AskingGoodQuestions]
Pandu Rangam
Greenhorn

Joined: Dec 08, 2006
Posts: 24
if the constructor is private, then is it a singleton. I mean Math,Runtime, System etc are following Singleton design pattern?
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Pandu Rangam:
if the constructor is private, then is it a singleton. I mean Math,Runtime, System etc are following Singleton design pattern?


No. Singleton implies private constructor, but private constructor does not imply Singleton.

A private constructor may be used to help to forbid any instantiation of a utility class. It may also be used for instantiable classes whose public construction interface is a factory method, rather than a constructor. Type-safe enums, pre Java 5, are another use. There are probably more.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Private Constructors in j2se
 
Similar Threads
prevent constructors from being instantiating
default method
Prospectus for J2ME
method visibility
is there any API to access private members of a class?