2008 I watched Joshua Bloch explained a new way to implement the Singleton pattern with the enum which was introduced in Java 5 (2004). It is easy, small and safe, but it seems that the most widely used way is still the old (thread)unsafe static class method with lazy loading:

public class StaticSingleton {
   private static StaticSingleton INSTANCE;

   private StaticSingleton() {}

   public static StaticSingleton getInstance() {
      if ( INSTANCE == null ) {
         INSTANCE = new StaticSingleton();
      }
      return INSTANCE;
   }
}

This works fine for the most parts, and there are lengthy columns written about this and how to make it safer like this:

public class StaticSingleton {
   private volatile static StaticSingleton INSTANCE;

   private StaticSingleton() {}

   public static synchronized StaticSingleton getInstance() {
      if ( INSTANCE == null ) {
         INSTANCE = new StaticSingleton();
      }
      return INSTANCE;

   }
}

but will make a performance hit if getInstance() is called a lot. The other way is only synchronize the instantiation only by doing a double check.

public class StaticSingleton {
   private volatile static StaticSingleton INSTANCE;

   private StaticSingleton() {}

   public static StaticSingleton getInstance() {
      if ( INSTANCE == null ) {
         synchronized {
            if ( INSTANCE == null ) {
               INSTANCE = new StaticSingleton();
            }
         }
      }
      return INSTANCE;
   }
}

This is probably the best solution of the above, but if there is not a lot of work when instantiating the class the easiest way is to do this:

public class StaticSingleton {
   private static final StaticSingleton INSTANCE = new StaticSingleton();

   private StaticSingleton() {}

   public static StaticSingleton getInstance() {
      return INSTANCE;
   }
}

This will make it thread safe because all static members will be created before the class can be used, but we have not addressed the problem with serialization. Or we could use what Joshua proposed, using enum:

public enum Music {
   INSTANCE;
}

Like this:

public enum Music {
   INSTANCE;

   private final String[] favoritGenre = { “Progressive House”, “Minimal Techno” };

   public String[] getFavoriteGenre() {
      return Arrays.toString(favoritGenre);
   }
}

Or as Joshua himself states in the book Effective Java:

“This approach is functionally equivalent to the public field approach, except that it is more concise, provides the serialization machinery for free, and provides an ironclad guarantee against multiple instantiation, even in the face of sophisticated serialization or reflection attacks. While this approach has yet to be widely adopted, a single-element enum type is the best way to implement a singleton.”