Singleton Class-Private Constructor

A class is called a singleton class, if it allows only one instance of the object to be created throughout the application.

A singleton class has the following

  1.  private constructor which-prevent other classes from instantiating it directly.
  2. a public method with static modifier which returns the instance.--a static method can be accessed at class level without     creating an object.
  3. private static instance of the class

package singleotons;

Public class Logger{
private static Logger logger;

private Logger(){

public static Logger getLoggerInstance(){
if (logger==null){

logger=new Logger();
return logger;


Popular posts from this blog

Spring MVC- Redirect from one controller to another

Jquery Table Inline Edititing