Java / Quarkus Interview questions
What is the purpose of the @ApplicationScoped annotation?
@ApplicationScoped is a CDI scope annotation that marks a bean to be created once and shared as a single instance for the lifetime of the entire application, which is the standard choice for stateless services, repositories, and clients that don't need per-request state.
@ApplicationScoped public class GreetingService { public String greet(String name) { return "Hello, " + name; } }
It contrasts with other CDI scopes like @RequestScoped (a new instance per HTTP request) or @Singleton (also one instance, but without the proxy-based lazy initialization and contextual behavior that @ApplicationScoped beans get); choosing the wrong scope for a stateful bean can lead to subtle bugs like one user's request data leaking into another's if a bean meant to be request-scoped is accidentally shared application-wide.
In Quarkus specifically, favoring @ApplicationScoped for simple stateless beans also plays well with native-image build-time optimization, since a single, predictable instance is easier for ArC to resolve and wire ahead of time.
More Related questions...
