Java / GraalVM Interview questions
What is the difference between build-time and run-time class initialization?
These are the two possible moments a class's static initializer can execute in a Native Image application, and the choice changes both correctness and performance.
| Build-time initialization | Run-time initialization |
| Static initializer runs during the native-image build | Static initializer runs on first use, same as a normal JVM |
| Resulting state baked into the image heap | State computed fresh on the target machine |
| Faster startup, but risks stale/wrong values if the environment differs between build and run machines | Slightly slower first access, but always environment-correct |
Run-time initialization is the safe default, and it's what Native Image uses unless a class is explicitly opted into build-time initialization via --initialize-at-build-time=<class> or annotated by a framework's build-time processor.
More Related questions...