Q-1). What is a Singleton Design Pattern?
A-1). Singleton ensures only one instance of a class exists and provides global access.
Q-2). What are real-world use cases of the Singleton Pattern?
A-2). Used in logging, database connection pools, configuration settings, and caching.
Q-3). How do you make a Singleton class thread-safe in Java?
A-3). Using synchronized, double-checked locking, or Bill Pugh Singleton.
Q-4). How can you prevent breaking Singleton using Reflection?
A-4). Throw an exception in the constructor if an instance already exists.
Q-5). Why is volatile needed in the Double-Checked Locking Singleton?
A-5). Prevents reordering of instructions and ensures visibility of instances across threads.
Q-6). How do you prevent Singleton from being cloned?
A-6). Override clone() and throw CloneNotSupportedException.
Q-7). What are the drawbacks of the Singleton Pattern?
A-7). It can cause tight coupling, unit testing difficult, and introduce global state risks.
Q-8). Can Singleton be used in distributed systems?
A-8). In distributed systems, a single JVM can’t maintain a global Singleton, so Registry-based Singleton or Database-backed Singleton is used.