Skip to main content

Explain the Singleton design pattern in Java.

Mid Java
Quick Answer Singleton ensures only one instance of a class exists. Implementation: private constructor, static getInstance() method. Thread-safe options: eager initialization (static final field), synchronized getInstance() (slow), double-checked locking with volatile (fast, correct in Java 5+), or the enum singleton (simplest and thread-safe by JVM guarantee). Use dependency injection instead of Singleton where possible.

Answer

Ensures one instance of a class exists.
Implement using eager loading, lazy loading, double-checked locking, or enum.
Provides global access to the instance.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice