Java / GraalVM Interview questions
What is class initialization at build time?
By default, Native Image initializes most application classes at run time, the first time they're used, mirroring normal JVM semantics.
However, you can explicitly force a class to be initialized during the native-image build instead, which means its static initializer runs once at build time and the resulting static field values are baked directly into the executable's image heap.
native-image --initialize-at-build-time=com.example.Config MyApp
This is useful for cutting startup work - for example, precomputing a large static lookup table - but it's risky if that initializer depends on things that differ between the build machine and the run machine, like file paths, environment variables, or random seeds, since those values would get frozen in at build time instead of being computed fresh at runtime.
More Related questions...