java singleton

Java
public class SingletonOnDemand {
	
	private SingletonOnDemand () {}
	private static class Singleton {
		private static final SingletonOnDemand instance = new SingletonOnDemand();
	}
	
	public static SingletonOnDemand getInstance () {
		System.out.println("create instance");
		return Singleton.instance;
	}
}public class SingletonClass {
    private static final SingletonClass SINGLE_INSTANCE = new SingletonClass();
    private SingletonClass() {}
  public static SingletonClass getInstance() {
      return SINGLE_INSTANCE;
    }
}
Source

Also in Java: