• Post Reply Bookmark Topic Watch Topic
  • New Topic

Singleton in java  RSS feed

 
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: 9610
37
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
Sheriff
Posts: 16007
87
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
Boost this thread!