GraalVM and Quarkus: A Brief introduction for Java Beginners

Mary Reni
Javarevisited
Published in
3 min readMar 20, 2021

--

When I started coding, I did not understand why Java code needs a virtual machine (JVM). If you are also confused about it, please read the next three paragraphs. Others can skip it.

Build once, Run anywhere.

This was the mantra for Java. Wherever you write your code, be it Mac or Linux, when you compile it with JDK, it creates a byte-code (your class files). You can package your class files into a jar file and transfer it to any platform to run it.

This was very helpful since this ensured faster releases with traditional application servers. All you have to ensure is that the java version used for compilation and the Java runtime in the target machine are compatible. This means that the Runtime java version should not be less than the compiler Java version. Otherwise, you would get java. lang.UnsupportedClassVersionError

But this byte code is not a native executable, you cannot run it standalone in the target machine.

So with Java, you actually need a mediator who talks to the host OS, to execute the application you have written. We call this mediator, a JVM. It is called a VM as it does the functionalities of OS like Garbage Collection or Memory Management, Thread Scheduling, and much more. There are multiple JVM implementations, the most popular one is Hotspot JVM.

JVM is very helpful, but it takes more time for initial startup.

With cloud-native environments like Kubernetes, pods are fired on the increased load within seconds. If it takes multiple seconds for a Java application itself to startup, it would be a disappointment. This is also the reason Java is not very popular in the Serverless world (the infamous Cold start problem).

Also, when everyone is packaging their code as a container image, we need not have to worry about platform compatibility. If possible, instead of copying the Jar file into a Java image and shipping it, we can ship the optimized native image itself. This is what we call, a cloud-native technology.

What is GraalVM?

GraalVM is an advanced runtime with a lot of features like Ahead-of-Time compilation, tuned for performance. A JVM can only run byte-code languages like Java, Kotlin, Scala; but GraalVM can work with a range of programming languages like R, Python, NodeJS, and so on. Truffle Language Implementation framework is used for having this polyglot functionality. GraalVM improves java startup time in multifold with native-image technology.

What is a native image?

A native image is a platform-specific standalone executable created from JVM based languages like Java, Kotlin, or Scala. Optionally, other guest languages can also be compiled into it.

GraalVM provides a utility called native-image to create these native images. There are also few Java frameworks that compile the application code into a native executable instead of a jar or war package.

What is Quarkus?

Quarkus is a java framework, created and optimized in every way to work with cloud and high-performance environments. With Netty and Vert.x for imperative and reactive development, Quarkus also supports the compilation of java code to a native executable.

Quarkus needs GraalVM installation for building the native executables. A short performance difference of Quarkus can be seen here.

--

--