Prev Next

Java / Quarkus Interview questions

Explain the internal working of Quarkus's build-time class initialization?

Quarkus and GraalVM distinguish between classes initialized at build time (their static initializers run once during the native-image build, and the resulting state is baked directly into the binary) and classes initialized at runtime (static initializers run fresh each time the application process starts), and getting this classification right matters for both correctness and performance.

flowchart TD A[Class encountered during native-image analysis] --> B{Classified as build-time or runtime initialized?} B -- Build-time --> C[Static initializer runs once during build] C --> D[Resulting object state embedded into native binary image heap] B -- Runtime --> E[Static initializer deferred] E --> F[Runs fresh on every process start]

By default, most application and framework classes are build-time initialized for maximum startup benefit, since baking already-initialized state into the binary avoids repeating that work on every process launch; but this becomes incorrect for classes whose state legitimately needs to differ per environment or per run — a class holding a random seed, a class that opens a file handle, or one that reads an environment variable that should reflect the actual runtime environment, not whatever was present at build time.

Quarkus and its extensions mark such classes for runtime initialization explicitly (via GraalVM's --initialize-at-run-time configuration, often applied automatically by an extension's build steps), and a common cause of subtle native-image bugs — like a "random" value that's identical on every single process restart — traces directly back to a class that should have been runtime-initialized but was build-time-initialized instead.

What happens to a build-time-initialized class's static state?
What kind of bug can result from a class being incorrectly build-time-initialized?

More Related questions...

What is Quarkus? What is the purpose of Quarkus? What are the key features of Quarkus? What is GraalVM in the context of Quarkus? What is Supersonic Subatomic Java? What are the two runtime modes of Quarkus? What is a native executable in Quarkus? What is Quarkus Dev Mode? What are Quarkus extensions? How do you create a new Quarkus project? What is the Mutiny library used for in Quarkus? What is Panache in Quarkus? What are the types of Panache entity patterns available? What is CDI in Quarkus? What is the purpose of the @ApplicationScoped annotation? What is RESTEasy Reactive in Quarkus? Define Quarkus configuration profiles? What is application.properties used for in Quarkus? List the build tools supported by Quarkus? What is a Quarkus BuildItem? What is the difference between Quarkus and Spring Boot? Why does Quarkus have faster startup time than traditional Java frameworks? How does Quarkus achieve low memory footprint? Explain the build-time vs runtime processing model in Quarkus? What is the difference between JVM mode and native mode in Quarkus? How does Quarkus support GraalVM native image compilation? Explain the lifecycle of a Quarkus application build? What happens when you run "quarkus dev"? How do you configure a Quarkus application for different environments using profiles? What is the difference between @Inject and @ConfigProperty in Quarkus? How does dependency injection work in Quarkus vs traditional CDI containers? Explain the internal working of Quarkus extensions? What is the difference between imperative and reactive programming in Quarkus? How does Quarkus handle reactive messaging with Kafka? When should you use Quarkus over a traditional Spring application? What is the difference between Panache Active Record and Repository pattern? How do you write integration tests in Quarkus using @QuarkusTest? Explain the execution flow of a REST request in Quarkus using RESTEasy Reactive? How does Quarkus support GraalVM substitutions for native compilation issues? What is the difference between Quarkus and Micronaut? How do you troubleshoot a native image build failure in Quarkus? Explain the lifecycle of application startup in native mode vs JVM mode? How does Quarkus achieve ahead-of-time (AOT) compilation benefits? What is the role of the Quarkus Arc container? How do you secure a Quarkus application with OIDC? Explain the internal working of Quarkus's build-time class initialization? How does Quarkus support Kubernetes-native deployments? What is the difference between Quarkus's Vert.x-based reactive engine and traditional servlet-based engines? How do you optimize Quarkus native image build times? Explain the execution flow of a reactive messaging pipeline using SmallRye Reactive Messaging in Quarkus?
Show more question and Answers...

Spring

Comments & Discussions