You are designing a system where it is critical to have only one instance of a configuration manager. How would you implement the Singleton pattern?

The Singleton Pattern ensures that a class has only one instance throughout the application's lifecycle and provides a global access point to that instance. It is commonly used for shared resources such as configuration managers, logging services, caching systems, and database connection managers where multiple instances could lead to inconsistent behavior.

Key Points

Example

A ConfigurationManager stores application settings such as database URLs, API keys, and environment properties. Having multiple instances could result in inconsistent configuration data, so a Singleton ensures that all components access the same configuration object.

public enum ConfigurationManager {

    INSTANCE;

    private String environment =
            "Production";

    public String getEnvironment() {

        return environment;
    }

    public void setEnvironment(
            String environment) {

        this.environment = environment;
    }
}

public class Main {

    public static void main(String[] args) {

        ConfigurationManager config =
                ConfigurationManager.INSTANCE;

        System.out.println(
                config.getEnvironment());
    }
}

Interview Tip

A concise interview answer is: I would implement the ConfigurationManager as a Singleton to guarantee a single shared instance across the application. The most robust approach is using an enum-based singleton because it is thread-safe by default and protects against issues caused by reflection, serialization, and cloning.

Last updated: 16 July 2026

Previous question: How would you ensure atomicity without using the synchronized keyword?

Next question: Describe a scenario where custom exceptions would be a better solution than built-in ones.

More Core Java - Level IV (Advanced) interview questions

All Core Java - Level IV (Advanced) questions