Simple Java singleton example

// May 26th, 2009 // 5 Comments // Programming

public class SimpleSingleton {
  private static SimpleSingleton singleInstance =  new SimpleSingleton();

  //Marking default constructor private
  //to avoid direct instantiation.
  private SimpleSingleton() {}

  //Get instance for class SimpleSingleton
  public static SimpleSingleton getInstance() {

  return singleInstance;
  }
}

5 Responses to “Simple Java singleton example”

  1. Thirty Days says:

    Nice Post, Thanks.

  2. thanks mas.. saya nambah ilmu nih

  3. Thanks for the example.I have been associated with JAVA technology for last 10 years now.Singleton is the most important aspect of the JAVA as it is very useful in wide range of object designs.One thing which is very important while implementing the singleton is “the thread has to be synchronised.

  4. JoshieGeek says:

    This is a good article for me to read. Btw, I live in Indonesia too. In Yogyakarta. Are you a Java Programmer? Because I am.

Leave a Reply