What are design patterns in Java?
Design patterns are proven, reusable solutions to commonly recurring software design problems. They are not code libraries or algorithms — they are templates describing how to structure classes and objects to solve a specific type of design challenge. The term was popularized by the Gang of Four (GoF) book (Gamma, Helm, Johnson, Vlissides, 1994), which cataloged 23 fundamental patterns.
The GoF patterns are organized into three categories. Creational patterns address object creation: Singleton (one instance), Factory Method (defer instantiation to subclasses), Abstract Factory (families of related objects), Builder (step-by-step construction of complex objects), and Prototype (clone-based creation). Structural patterns address class and object composition: Adapter (compatibility bridge between interfaces), Decorator (add behavior dynamically without subclassing), Facade (simplified interface to a complex subsystem), Proxy (controlled access to another object), and Composite (tree structures of objects). Behavioral patterns address communication and responsibility: Strategy (interchangeable algorithms), Observer (event notification), Command (encapsulate requests as objects), Iterator (sequential access), Template Method (define skeleton, defer steps to subclasses), and Chain of Responsibility.
Java's standard library embeds many of these patterns. java.util.Iterator is the Iterator pattern. java.io streams use Decorator heavily. java.lang.Runtime.getRuntime() is Singleton. The Collections.sort(list, comparator) API is Strategy. java.util.Observable (deprecated) was Observer.
Patterns have tradeoffs. Singleton introduces global state, making testing harder. Deep Decorator chains become hard to debug. Overusing patterns adds accidental complexity. The key is recognizing the problem a pattern solves and applying it deliberately, not pattern-matching for its own sake.
In interviews, naming patterns is table stakes. Demonstrating which problem each pattern solves and when not to use it distinguishes senior-level thinking.
Names the three GoF categories with at least two patterns per category, and gives one concrete example from the Java standard library.
Explains what a pattern is vs. an algorithm/library, names the three categories with representative patterns, provides multiple JDK examples, and discusses a tradeoff or anti-pattern context.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment