Java 8 vs Java 25: Shrinking Runtime Sizes with JPMS

Do You Really Need the Entire JDK to Print “Hello World”? In Java 8: Simple hello world program → 210 MB runtime In Java 25: Same program → 47 MB modular runtime I tried executing the below program on two different Java versions( java 8 and java 25): public class JPMSPOCExample {   public static void main(String[] args) {     System.out.println("Hello JPMS");   } } That’s it. No SQL. No XML. No Networking. Just a simple main(). 🔹 Java 8 Runtime Reality On my system: • Full JRE size → 210 MB • rt.jar inside JRE → ~60 MB Even this tiny program implicitly depended on the entire runtime. That included: java.sql java.desktop java.rmi XML APIs and many other modules There was no way to trim unused parts. Everything was bundled together inside rt.jar. 🔹 Java 25 + JPMS + jlink Now let’s see what happens in Java 25. Step 1 — Compile javac JPMSPOCExample.java Step 2 — Create JAR jar --create --file jpmspoc.jar JPMSPOCExample.class Step 3 — Detect Required Modules jdeps --print-module-deps jpmspoc.jar Output: java.base That’s it. The program only needs java.base. Step 4 — Create Minimal Runtime jlink --add-modules java.base --output minimal-runtime The above creates a folder called "minimal-runtime" Minimal runtime size on my system → 47 MB Step 5 — Run Using Custom Runtime minimal-runtime/bin/java -cp jpmspoc.jar JPMSPOCExample Output: Hello JPMS Conclusion : Simple Hello world program using java 8 requires 210 MB runtime , whereas on java 25 using jlink takes 47 MB modular runtime Now let’s translate that into enterprise impact. 1️⃣ Smaller Docker Images In enterprise environments, If your base image shrinks by ~160 MB: ▪️Faster image pull in Kubernetes ▪️Faster CI/CD pipeline ▪️Faster scaling In large clusters (100+ pods), this becomes significant. Even saving 100 MB per container × 200 pods = 20 GB less transfer during scaling events. Architectural Takeaway Adopting JPMS at the application level is a structural decision. As discussed in my previous post, for many Spring-based REST backends, full modularization may not deliver proportional benefits due to heavy reflection usage. However , Even if we do not introduce module-info.java in our codebase, we should still understand the modular structure of the JDK we are running on. At minimum, we should: • Use jdeps to identify the exact modules our application depends on • Use jlink to build a runtime image that includes only those modules • Avoid shipping unnecessary parts of the JRE into production Note - Jlink will not be useful,If JDK is pre-installed on your prod environment Have you leveraged jlink to build trimmed runtime images in production environments? I’d genuinely love to hear from the community — Did it translate into measurable improvements in: • Container image size? • Startup latency? • Memory footprint? • Overall infrastructure efficiency? Real-world feedback would be extremely valuable. #Java #SpringBoot #SoftwareArchitecture #BackendDevelopment #JPMS #JLink

To view or add a comment, sign in

Explore content categories