What is the difference between the Strategy and State patterns?

Strategy and State are behavioral design patterns that use composition and polymorphism, but they solve different problems. The Strategy Pattern focuses on selecting one algorithm or behavior from multiple alternatives, whereas the State Pattern allows an object to change its behavior automatically when its internal state changes.

Key Points

Example

A payment application may use the Strategy Pattern to choose between Credit Card, UPI, or PayPal payment methods. A document workflow system may use the State Pattern where a document behaves differently in Draft, Review, and Published states.

interface PaymentStrategy {

    void pay();
}

class CreditCardPayment
        implements PaymentStrategy {

    public void pay() {
        System.out.println(
                "Paid using Credit Card");
    }
}

class UpiPayment
        implements PaymentStrategy {

    public void pay() {
        System.out.println(
                "Paid using UPI");
    }
}

public class Main {

    public static void main(String[] args) {

        PaymentStrategy strategy =
                new UpiPayment();

        strategy.pay();
    }
}

Interview Tip

A concise interview answer is: The Strategy Pattern is used to select one behavior or algorithm from multiple alternatives, with the choice typically made by the client. The State Pattern is used when an object's behavior must change automatically based on its internal state. Strategy focuses on interchangeable algorithms, while State focuses on state-driven behavior changes.

Last updated: 16 July 2026

Previous question: How would Java 8 features, particularly streams and lambdas, enhance performance and maintainability?

Next question: How would you apply the Observer pattern in an event-driven application?

More Core Java - Level IV (Advanced) interview questions

All Core Java - Level IV (Advanced) questions