Write code for singleton pattern
Anoniem
public class Singleton{ private static Singleton uniqueInstance; private Singleton() {} //do noting in constructor public static Singleton getInstance(){ if (uniqueInstance == null ) { uniqeInstance = new Singleton(); } return uniqueInstance; } Source: Head First Design Patterns You need to class Singleton.getInstance() without explicitly creating an object. Since the constructor is private, only methods inside the class can invoke it. So the only way to create a new instance is through get the Instance() method. Once created, the if condition will not allow another new instance.