Design Patterns

Lombok @Builder

Lombok’s @Builder annotation is a useful technique to implement the builder pattern that aims to reduce the boilerplate code. In this tutorial, we will learn to apply @Builder to a class and other useful features. Ensure you have included Lombok in the project and installed Lombok support in the IDE. If we want to marshal …

State Design Pattern in Java

The State pattern lets a delivery respond differently as it moves from packed to shipped to delivered. Follow the Java example, diagrams, and invalid transition.

Mediator Design Pattern in Java

The Mediator pattern gives interacting objects one place for their coordination rules. Follow a Java chat room that routes messages and rejects an unknown recipient.

Observer Design Pattern in Java

The Observer pattern lets a publisher notify registered listeners. Follow a Java example where one listener unsubscribes during a notification and see who receives the next message.

Memento Design Pattern in Java

Learn the Memento pattern in Java with an article snapshot example, tested save and restore output, and practical notes on undo history and redo.

Proxy Design Pattern in Java

Learn the Proxy pattern in Java with a runnable lazy report example. See when loading occurs, how repeated reads behave, and the limits of caching and concurrency.

Flyweight Design Pattern in Java

Learn the Flyweight design pattern in Java with a runnable pen factory example. See what state to share, how the cache key works, and when reuse is worthwhile.

Facade Design Pattern in Java

Learn the Facade design pattern with a runnable Java report example, clear UML diagrams, and practical guidance on file errors and subsystem access.

Strategy Design Pattern in Java

Learn the Strategy pattern with UML diagrams and a Java checkout example that applies different discount policies. Includes runnable code and output.

Template Method Design Pattern in Java

Learn Template Method in Java with shipping quotes, a fixed calculation workflow, required steps, optional hooks, diagrams, and tested failure behavior.

Composite Design Pattern in Java

Learn the Composite design pattern with a runnable Java portfolio example. See how leaf and group objects share one operation, and how duplicate membership and overflow affect totals.

Bridge Design Pattern in Java

Learn the Bridge pattern in Java with a runnable report example. See how report types and output formats vary independently, and when to use Bridge.

Adapter Design Pattern in Java

Learn the Adapter pattern in Java with a runnable Fahrenheit-to-Celsius example, diagrams, and a failure case that preserves the sensor contract.

Builder Design Pattern in Java

Learn the Builder pattern in Java with classic, generic and Lombok implementations. Compare defaults, validation and mutable versus immutable results.

Decorator Design Pattern in Java

Learn how the Decorator pattern adds optional behavior through Java wrappers. Build a support-report example, trace call order, and run an order-sensitive demo.

Visitor Design Pattern in Java

Learn Visitor in Java with document export and statistics, complete code, double dispatch, diagrams, and tested visitor reuse and overload behavior.

Prototype Design Pattern in Java

Learn the Prototype pattern in Java with a newsletter campaign example. Compare shallow and deep copies, copy constructors, Cloneable and prototype registries.

Factory Design Pattern in Java

Learn simple factories and Factory Method in Java with working text and HTML preview examples, participant diagrams, output and error handling.

Singleton Design Pattern in Java

Learn how Java Singleton works with enum and holder implementations, runnable code, thread-safety limits, serialization, and practical alternatives.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.