• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singleton in java

 
Dinesh Tahiliani
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please explain me the meaning of Singleton with example ...
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well singleton is a pattern in which you can create only one instance of a class. You implement it by making the constructor private and creating a static factory method which sends the only object of the class to the caller.

This is a sample code-

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15452
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Singleton pattern in Wikipedia and Java Singleton Design Pattern.

Note that some people regard the singleton design pattern as an anti-pattern (a bad thing). See, for example Why Singletons Are Controversial.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic