Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Private Constructors in j2se

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one tell is there any class with a private constructor in j2se api other than Math class?
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, lots. java.lang.System and java.util.Arrays are the first two that come to mind.
 
Pandu Rangam
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the constructor is private, then is it a singleton. I mean Math,Runtime, System etc are following Singleton design pattern?
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic