Singleton class in Java

This “Singleton class in Java” page is explaining rules to create user defined singleton class and how to work with singleton class in java application.


Singleton class:

  • Class must be public
  • Properties must be private
  • It is not allowed to instantiate the class directly(contains private constructor).
  • Using Factory method, we can get instance of this class.
  • “Factory method” is a static method available in Singleton-class.
  • “Factory method” creates an object and returns from its definition.


Note: The only difference between Factory class and Singleton class is, “Factory class” can be instantiated many times where as “Singleton” class only once.


Share this