Oracle Labs

Native Image

Native image is a technology to ahead-of-time compile Java code to a standalone executable, called a native image.

This executable includes the application classes, classes from its dependencies, runtime library classes, and statistically linked native code from JDK.

Native images can run with a smaller memory footprint and with much faster startup times. They are well suited to applications that are deployed using container images and are especially interesting when combined with “Function as a service” (FaaS) platforms.

Native Image is a technology to compile Java code ahead-of-time to a binary – a native executable.

Native executable

A native executable includes only the code required at run time, that is the application classes, standard-library classes, the language runtime, and statically-linked native code from the JDK.

Advantages of executable file produced by Native Image:

  • Uses fraction of the resources required by the Java Virtual Machine, so its cheaper to run
  • Starts milliseconds (very fast, just like what Go would do)
  • Delivers peak performance immediately, with no warmup
  • Can be packaged into a lightweight container image for fast and efficient deployment
  • Presents a reduced attack surface
    • What does this mean?

A native executable is created by the Native Image builder or native-image that processes your application classes and other metadata to create a binary for a specific operating system and architecture.

  • First, the native-image tool performs static analysis of your code to determine the classes and methods that are reachable when your application runs.
  • Second, it compiles classes, methods, and resources into a binary.
  • This entire process is called build time to clearly distinguish it from the compilation of Java source code to bytecode.