JAVA DESIGN PATTERN Questions and Answers

Mention in how many ways can you write singleton class in Java?

One can write singleton class in Java in four ways

  • Singleton with public static final field initialized during class loading
  • Singleton generated by static nested class, also referred as singleton holder pattern
  • Singleton by synchronizing get instance () method
  • From Java 5 on-wards using Enums