Prev Next

Java / GraalVM Interview questions

1. What is GraalVM? 2. What are the main components of GraalVM? 3. What is Native Image in GraalVM? 4. What is the Graal compiler? 5. What is the purpose of Substrate VM? 6. What are the editions of GraalVM? 7. How do you install GraalVM using SDKMAN? 8. How do you apply the gu utility to manage components? 9. Define polyglot programming in the context of GraalVM? 10. Describe the Truffle language implementation framework? 11. List the languages GraalVM can run? 12. What is ahead-of-time (AOT) compilation? 13. What are the benefits of using GraalVM Native Image? 14. What is a fallback image? 15. Describe reflection configuration in native image? 16. What is class initialization at build time? 17. How do you set GraalVM as your default JDK? 18. How do you generate a native executable with native-image? 19. What is the purpose of the Graal compiler's tiered execution? 20. Define the Graal compiler's JIT role within HotSpot? 21. What are the types of GraalVM components installable via gu? 22. Describe the polyglot Context API? 23. What is the purpose of Truffle's Partial Evaluation? 24. Explain the purpose of resource-config.json in native image? 25. What is the purpose of the reachability metadata repository? 26. Why is GraalVM's JIT compiler often faster than the default HotSpot C2 compiler? 27. What is the difference between GraalVM Community and Enterprise editions? 28. When should you choose Native Image over running on the JVM? 29. How does the native-image build process work end-to-end? 30. Why doesn't Native Image support dynamic class loading by default? 31. How do you troubleshoot "ClassNotFoundException" in a native image at runtime? 32. What is the difference between build-time and run-time class initialization? 33. How can you optimize native image build time for large applications? 34. Why should you use Profile-Guided Optimization (PGO) with Native Image? 35. How does escape analysis work in the Graal compiler? 36. Explain the execution flow of a polyglot call between Java and JavaScript on GraalVM? 37. What happens when you use Java dynamic proxies with Native Image? 38. Why is heap size configuration different for native image versus a JVM? 39. How do you troubleshoot missing reflection metadata errors during native image build? 40. Explain the internal working of Truffle's AST specialization? 41. Difference between Espresso and running native Java bytecode on the JVM? 42. Why doesn't Native Image support arbitrary bytecode generation at runtime? 43. How can you optimize the memory footprint of a native image executable? 44. Explain the lifecycle of a Truffle language implementation from parsing to execution? 45. Difference between GraalVM Native Image and traditional Docker-based JVM deployment for startup time? 46. How does GraalVM's deoptimization mechanism work when a speculative optimization fails? 47. When would you choose GraalVM Enterprise's G1 GC support over Community's Serial GC for native image? 48. How do you debug a native image application when standard Java debuggers don't attach? 49. Explain the internal working of the Graal compiler's speculative optimizations? 50. Why is GraalVM particularly well suited for serverless and microservices workloads?

1. What is GraalVM?

GraalVM is a high-performance runtime distributed by Oracle that extends the JVM with a new just-in-time compiler and the ability to run non-JVM languages on the same runtime. At its core sit two pieces: the Graal compiler , a JIT written in Java that replaces or augments HotSpot's C2 compiler, a...

Read full answer

2. What are the main components of GraalVM?

GraalVM is made up of a handful of distinct pieces that work together rather than one monolithic tool. Component Role Graal compiler JIT/AOT compiler written in Java, plugs into HotSpot as a replacement for C2 Truffle Framework for building fast language interpreters (JS, Python, Ruby, R, WASM) S...

Read full answer

3. What is Native Image in GraalVM?

Native Image is the GraalVM utility that ahead-of-time (AOT) compiles a Java application, together with the JDK classes it actually uses, into a single self-contained native executable. Instead of starting a JVM, loading classes, and warming up the JIT before reaching peak performance, the result...

Read full answer

4. What is the Graal compiler?

The Graal compiler is a dynamic, just-in-time compiler written entirely in Java that can run inside the HotSpot JVM as a replacement for the default C2 compiler. Because it's written in Java rather than C++, it's easier to extend and reason about, and it exposes a graph-based intermediate represe...

Read full answer

5. What is the purpose of Substrate VM?

Substrate VM is the lightweight runtime that gets embedded into every Native Image executable to provide the services a Java program needs that the OS doesn't give for free. That includes its own garbage collector, thread scheduling, exception handling, and synchronization - essentially a strippe...

Read full answer

6. What are the editions of GraalVM?

GraalVM is distributed in a few editions that differ mainly in optimization level, licensing, and support. GraalVM Community Edition (CE) - free, open-source, includes the core JIT compiler, Truffle, and Native Image with a serial or epsilon garbage collector for native images. Oracle GraalVM (th...

Read full answer

7. How do you install GraalVM using SDKMAN?

SDKMAN is the most common way developers manage multiple GraalVM versions alongside other JDKs on macOS and Linux. sdk install java 21.0.2-graalce sdk use java 21.0.2-graalce java -version The candidate identifier suffix tells SDKMAN which distribution to fetch - -graalce pulls GraalVM Community ...

Read full answer

8. How do you apply the gu utility to manage components?

gu is GraalVM's command-line component manager, used to add or remove optional pieces that aren't bundled in the base download. gu list gu install nodejs gu install python gu remove nodejs gu list shows what's already installed, gu available shows what can be added, and gu install dow...

Read full answer

9. Define polyglot programming in the context of GraalVM?

Polyglot programming on GraalVM means writing an application where multiple languages - say Java, JavaScript, and Python - run in the same process, on the same runtime, and can call into each other directly without serialization or inter-process communication. This is possible because every suppo...

Read full answer

10. Describe the Truffle language implementation framework?

Truffle is a framework for writing language interpreters as simple tree-walking AST interpreters, while still getting competitive just-in-time compiled performance. The trick is that Truffle interpreters use self-specializing nodes : each AST node starts generic, then rewrites itself to a faster,...

Read full answer

11. List the languages GraalVM can run?

GraalVM natively runs standard JVM languages - Java, Kotlin, Scala, and Groovy - since they already compile to JVM bytecode. On top of that, through Truffle-based implementations it can also execute: JavaScript and Node.js (GraalJS) Python (GraalPy) Ruby (TruffleRuby) R (FastR) WebAssembly (Wasm)...

Read full answer

12. What is ahead-of-time (AOT) compilation?

Ahead-of-time compilation means translating code into machine instructions before the program runs, as a build step, rather than compiling hot methods on the fly while the program executes (just-in-time compilation). In GraalVM, Native Image performs AOT compilation: it statically analyzes every ...

Read full answer

13. What are the benefits of using GraalVM Native Image?

Native Image's biggest wins show up in a handful of measurable areas compared to running the same app on a standard JVM. Benefit Typical Impact Startup time Milliseconds instead of hundreds of milliseconds to seconds Memory footprint Lower resident memory, no JIT/interpreter data structures at ru...

Read full answer

14. What is a fallback image?

A fallback image is what native-image produces when it can't fully complete static analysis or AOT compilation of the application - for example, if it detects unsupported reflective or dynamic behavior it can't resolve at build time. Instead of failing the build outright, it emits a small wrapper...

Read full answer

15. Describe reflection configuration in native image?

Because Native Image performs a closed-world static analysis at build time, it can only see the classes, methods, and fields that its analysis can prove are reachable from the entry point - reflective calls built from a runtime string (like Class.forName(someVariable) ) are invisible to it. To fi...

Read full answer

16. 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 an...

Read full answer

17. How do you set GraalVM as your default JDK?

On most systems this is a matter of pointing JAVA_HOME and your PATH at the GraalVM installation directory. export JAVA_HOME = /path/to/graalvm-jdk-21 export PATH = $JAVA_HOME / bin : $PATH java - version If you manage JDKs with SDKMAN, sdk default java 21.0.2-graalce does the same thing persiste...

Read full answer

18. How do you generate a native executable with native-image?

The simplest path is compiling your Java source to class files, then pointing native-image at the main class. javac HelloWorld.java native-image HelloWorld ./helloworld For a real Maven or Gradle project, it's more common to build a fat jar first and pass that: native-image -jar target/myapp.jar ...

Read full answer

19. What is the purpose of the Graal compiler's tiered execution?

Tiered compilation is a strategy where code starts out running in a cheap mode and only gets progressively more expensive optimization applied once it's proven to be worth it, balancing startup latency against peak throughput. Tier Behavior Interpreter / C1-like Fast to produce, collects executio...

Read full answer

20. Define the Graal compiler's JIT role within HotSpot?

Inside a standard HotSpot JVM, the Graal compiler can be enabled as the top-tier JIT compiler, plugging in through HotSpot's JVMCI (JVM Compiler Interface) as a replacement for the default C2 compiler. HotSpot still handles interpretation and lower-tier compilation the same way it always has; onc...

Read full answer

21. What are the types of GraalVM components installable via gu?

gu -installable components generally fall into a few categories, depending on the GraalVM distribution and version. Language runtimes - Node.js/JavaScript, Python, Ruby, R, LLVM toolchain Tools - the Chrome DevTools-based debugger ( chrome-debugger ), profiling tools like VisualVM integration Nat...

Read full answer

22. Describe the polyglot Context API?

org.graalvm.polyglot.Context is the main entry point for embedding and running guest languages from Java host code. try (Context context = Context.create()) { Value result = context.eval( "js" , "1 + 2" ); System.out.println(result.asInt()); } A Context represents an isolated execution environmen...

Read full answer

23. What is the purpose of Truffle's Partial Evaluation?

Partial evaluation is the compilation technique the Graal compiler applies to Truffle interpreters to turn a generic "interpret this AST node" loop into specialized machine code for one specific piece of guest code. Conceptually, the interpreter itself is treated as a program to be compiled: give...

Read full answer

24. Explain the purpose of resource-config.json in native image?

Because Native Image's static analysis can't know which files your application will load via Class.getResourceAsStream or similar calls with a runtime-computed path, any resource that needs to be bundled into the final executable must be listed explicitly. { "resources" : { "includes" : [ { "patt...

Read full answer

25. What is the purpose of the reachability metadata repository?

The GraalVM Reachability Metadata Repository is a community-maintained collection of pre-written reflection, resource, JNI, and proxy configuration files for popular third-party libraries. Instead of every project having to run the tracing agent against dependencies like Jackson, Hibernate, or va...

Read full answer

26. Why is GraalVM's JIT compiler often faster than the default HotSpot C2 compiler?

Graal tends to outperform C2 on certain workloads because of differences in its intermediate representation and optimization pipeline, not because it's simply "newer." Graal uses a unified sea-of-nodes graph IR that represents both control flow and data flow together, which makes global optimizat...

Read full answer

27. What is the difference between GraalVM Community and Enterprise editions?

The lines here have shifted over recent releases, but the practical distinctions have historically centered on optimization depth and garbage collection options for native images. GraalVM Community Oracle GraalVM (former Enterprise) Free, fully open source Free to use under Oracle's GraalVM Free ...

Read full answer

28. When should you choose Native Image over running on the JVM?

Native Image makes sense when startup latency and memory footprint dominate your cost or user experience more than raw sustained throughput does. Serverless functions - cold-start time directly affects billed duration and perceived latency. CLI tools - users expect a command to respond instantly,...

Read full answer

29. How does the native-image build process work end-to-end?

The build pipeline can be thought of as several sequential phases. flowchart TD A[Classpath + entry point] --> B[Points-to static analysis] B --> C[Build-time class initialization] C --> D[Universe/heap snapshot creation] D --> E[AOT compilation via Graal compiler] E --> F[Linking with Substrate ...

Read full answer

30. Why doesn't Native Image support dynamic class loading by default?

Native Image's entire performance model rests on a closed-world assumption : every class that could ever run must be known and analyzed at build time, so the compiler can strip out anything unreachable and compile the rest directly to machine code with no runtime lookup overhead. Dynamic class lo...

Read full answer

31. How do you troubleshoot "ClassNotFoundException" in a native image at runtime?

This almost always means the class was reachable only through reflection or a dynamic lookup that the build-time static analysis couldn't see, so it was stripped out of the final executable. Re-run the application on a normal JVM under the native-image-agent : java -agentlib:native-image-agent=co...

Read full answer

32. 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 fi...

Read full answer

33. How can you optimize native image build time for large applications?

Native image builds of large enterprise codebases can take many minutes, but several levers reliably cut that down. Increase build parallelism and memory with -J-Xmx and letting the builder use more CPU cores - the points-to analysis phase is the most parallelizable part. Reduce reachable surface...

Read full answer

34. Why should you use Profile-Guided Optimization (PGO) with Native Image?

Because a native image is compiled entirely ahead of time with no live runtime profiling feedback loop like a JIT gets, the compiler has to make static guesses about which branches are hot and which methods are worth inlining aggressively - guesses that are often wrong for real-world traffic patt...

Read full answer

35. How does escape analysis work in the Graal compiler?

Escape analysis determines whether an object allocated inside a method can ever be referenced ("escape") outside that method's scope - by being returned, stored in a field, or passed to another thread. If Graal proves an object never escapes, it can perform scalar replacement : instead of allocat...

Read full answer

36. Explain the execution flow of a polyglot call between Java and JavaScript on GraalVM?

A polyglot call walks through several layers before returning a result back to Java host code. sequenceDiagram participant Host as Java Host Code participant Ctx as polyglot.Context participant JS as GraalJS (Truffle) participant Graal as Graal Compiler Host->>Ctx: context.eval("js", source) Ctx-...

Read full answer

37. What happens when you use Java dynamic proxies with Native Image?

java.lang.reflect.Proxy normally generates a new class implementing given interfaces at runtime, backed by bytecode the JVM synthesizes on the fly - which directly conflicts with Native Image's closed-world, build-time-only class generation model. To make this work, Native Image needs to know at ...

Read full answer

38. Why is heap size configuration different for native image versus a JVM?

A standard JVM defaults its heap sizing based on available system memory and lets you tune it with familiar flags like -Xmx and -Xms at launch, with HotSpot's ergonomics adjusting things like young-generation size dynamically. A native image executable embeds its own garbage collector (Serial GC ...

Read full answer

39. How do you troubleshoot missing reflection metadata errors during native image build?

These errors typically surface as either a build-time warning about an unreachable class, or a runtime ClassNotFoundException / NoSuchMethodException in the finished binary. Reproduce the failing code path on a plain JVM with the tracing agent attached: -agentlib:native-image-agent=config-merge-d...

Read full answer

40. Explain the internal working of Truffle's AST specialization?

Every Truffle AST node starts life in an uninitialized/generic state - it doesn't yet know the concrete types of its operands. flowchart LR A[Uninitialized node] --> B{First execution} B --> C[Observe operand types] C --> D[Rewrite node to specialized variant] D --> E{Types stay stable?} E -->|Ye...

Read full answer

41. Difference between Espresso and running native Java bytecode on the JVM?

Espresso is a Java bytecode interpreter implemented as a Truffle language, meaning it runs Java bytecode as a guest language on top of GraalVM, rather than being the host JVM itself. Standard JVM execution Espresso (Truffle-based) HotSpot interprets/JIT-compiles bytecode as the host runtime Bytec...

Read full answer

42. Why doesn't Native Image support arbitrary bytecode generation at runtime?

Libraries like CGLIB, older versions of certain ORMs, and some AOP frameworks work by generating brand-new class bytecode on the fly at runtime - for example, subclassing an entity to add lazy-loading behavior - and then loading that freshly-minted class into the running JVM. Native Image's AOT c...

Read full answer

43. How can you optimize the memory footprint of a native image executable?

A handful of build- and run-time levers reliably shrink both the executable's disk size and its runtime memory usage. Trim reachable code : unused dependencies and overly broad reflection configs pull in classes the analysis then has to keep and compile, so removing them shrinks the binary direct...

Read full answer

44. Explain the lifecycle of a Truffle language implementation from parsing to execution?

Implementing a language on Truffle follows a fairly standard pipeline, even though the actual interpreter logic is developer-written. flowchart TD A[Source code] --> B[Lexer/Parser] B --> C[Truffle AST construction] C --> D[Tree-walking interpretation] D --> E[Node self-specialization on observed...

Read full answer

45. Difference between GraalVM Native Image and traditional Docker-based JVM deployment for startup time?

A traditional Docker image running a JVM app still pays the full JVM cost inside the container: JVM process startup, classloading for every used class, and JIT warm-up before the app reaches its steady-state throughput - typically hundreds of milliseconds to several seconds depending on app size,...

Read full answer

46. How does GraalVM's deoptimization mechanism work when a speculative optimization fails?

Both the Graal JIT and Native Image (for optimizations based on runtime profile assumptions) sometimes compile code based on a speculative assumption - for example, "this call site has only ever seen one concrete implementation, so inline it directly" - that might later turn out to be wrong. sequ...

Read full answer

47. When would you choose GraalVM Enterprise's G1 GC support over Community's Serial GC for native image?

Serial GC, the Community Edition default for native images, uses a single thread for collection work and keeps metadata overhead minimal - which is ideal for small heaps and short-lived processes where a GC pause simply doesn't have time to matter much. G1 GC (available via Oracle GraalVM) is a g...

Read full answer

48. How do you debug a native image application when standard Java debuggers don't attach?

A native executable is compiled machine code, not JVM bytecode, so a standard jdb /JDWP-based debugger that expects a live JVM to attach to has nothing to connect to. Build with debug info : native-image -g -O0 -jar app.jar embeds source-level debug symbols and disables optimizations that would o...

Read full answer

49. Explain the internal working of the Graal compiler's speculative optimizations?

Speculative optimization means the compiler generates code based on an assumption about runtime behavior that isn't provably always true, but is true often enough (based on collected profile data) to be worth betting on, backed by a safety net if the bet is wrong. flowchart TD A[Collect profile d...

Read full answer

50. Why is GraalVM particularly well suited for serverless and microservices workloads?

Serverless platforms bill (and rate-limit user-perceived latency) based largely on cold-start time, and microservices in orchestrated environments like Kubernetes are expected to scale instances up and down constantly in response to load - both scenarios where a standard JVM's startup-then-warm-u...

Read full answer

«
»

Comments & Discussions