JVM, JRE, and JDK: Understanding the Java Ecosystem

JVM, JRE, and JDK: Understanding the Java Ecosystem

Did you know that Java runs on more than 3 billion devices? From corporate mainframes to Android smartphones, Java continues to be one of the most ubiquitous programming languages in the technology world. Let's understand how this language manages to function across so many different systems through its unique architecture.

Introduction

The Java environment consists of three main components that work together: JVM (Java Virtual Machine), JRE (Java Runtime Environment), and JDK (Java Development Kit). Each has a specific role in the functioning of Java applications. In simplified terms, the JDK is the complete kit for developers to create Java programs, the JRE is the environment needed to run these programs, and the JVM is the engine that effectively executes the compiled Java code.

Basic Concepts

JVM ⚙️

The Java Virtual Machine, as the name suggests, is a virtual machine capable of interpreting compiled Java code. It's the component that allows Java applications to run on different platforms without needing recompilation.

To better understand this concept, here's an analogy:

💡 Imagine that Java's creator, James Gosling, had a perfect computer in his laboratory. This hypothetical computer would be capable of executing any Java program exactly as he envisioned, regardless of hardware or operating system peculiarities.
The JVM would be a virtual replica of this "ideal computer" inside any real device. It's as if every person who installs the JVM is receiving an exact copy of the execution environment that exists in the language creator's laboratory.

When Java code is written, it's compiled into an intermediate format called Bytecode.

About Bytecode 📝

Bytecode is the set of instructions that result from compiling Java source code. It's stored in files with the .class extension, and unlike languages such as C or C++, which compile directly to native machine code, Java is compiled into this intermediate format.

This intermediate format is nothing more than the native language of the virtual computer we mentioned above.

Therefore, when you run a Java program on any device - whether Windows, Linux server, Mac, or even an Android smartphone - you're running it inside the JVM installed on each mentioned device, hence the famous phrase that represents Java's philosophy:

🌎 "Write once, Run Anywhere"

Main JVM Components

  • Class Loader: Loads class files into memory;
  • Method Area: Stores method definitions and static code;
  • Heap: Manages memory for object allocation;
  • Stack: Stores local variables and partial results;
  • Execution Engine: Executes the instructions;
  • Garbage Collector: Automatic memory management, eliminating what has already been used in the program.

Performance Optimization 🚀

Although the JVM was initially considered slow because it interpreted bytecode, modern JVMs use Just-In-Time (JIT) compilation that identifies frequently executed code segments (hotspots) and compiles them to native code. This allows Java applications to achieve performance close to directly compiled languages like C++ in many cases.

Different JVM Implementations

There are several JVM implementations, each with specific characteristics:

  • HotSpot: Oracle/OpenJDK's standard implementation, focused on performance
  • OpenJ9: Developed by IBM and now in the Eclipse Foundation, optimized for lower memory consumption
  • GraalVM: A modern implementation that supports multiple languages
  • Azul Zing/Prime: Optimized for low latency and large heaps


JRE 🏠

The Java Runtime Environment includes the JVM plus the standard Java libraries needed to run Java applications. It's everything an end user needs to run Java programs.

Main Components

  • JVM: This is the heart of the JRE. The JVM is responsible for interpreting Java bytecode and converting it into machine instructions that the operating system can execute, as explained above;
  • Java Class Libraries: These libraries provide a set of predefined classes and interfaces that Java programs can use. They include classes for various tasks, such as string manipulation, input/output operations, networking, etc.
  • Java Classloader: It's the part of the JRE responsible for loading Java classes into memory. When a Java program is executed, the class loader locates and loads the classes needed to run the program.


JDK 🛠️

The Java Development Kit is a set of essential tools for developing Java applications. It includes everything the developer needs to write, compile, debug, and run Java code.

Additionally, it includes a complete copy of the JRE for running Java applications.

Main Development Tools:

  • `javac` (Java Compiler): This is the fundamental tool for transforming Java source code (.java) into Java bytecode (.class), which can be executed by the Java Virtual Machine (JVM). It's essential for the process of building any Java application.
  • `jar` (Java Archiver): This tool allows packaging Java class files and related resources into a single JAR (Java Archive) file. JAR files are used to distribute Java libraries and applications.
  • `jdb` (Java Debugger): A command-line tool for debugging Java programs. Allows setting breakpoints, inspecting variables, and tracking code execution.
  • `jconsole` (Java Monitoring Console): A monitoring tool that provides real-time information about the performance and resource utilization of running Java applications. Helps diagnose performance issues and resource consumption problems.
  • `jvisualvm` (Java Visual Analysis Tool): Visual analysis tool that provides detailed information about Java applications, including memory usage, threads, and CPU performance. Assists in detailed analyses of the internal workings of Java applications.


Java Versions and Editions 📅

Currently, Java follows a release cycle every six months, with sequentially numbered versions (Java 17, 18, 19... ). Some versions are designated as LTS (Long Term Support), such as Java 8, 11, 17, and 21, receiving security updates for longer periods.

Java is also offered in different editions:

  • Java SE: Standard Edition, for basic desktop and server applications
  • Jakarta EE (formerly Java EE): Enterprise Edition, for distributed enterprise applications
  • Java ME: Micro Edition, for mobile and embedded devices


Understanding the Relationships 🔄

The relationship between them is hierarchical:

  • The JDK contains the JRE
  • The JRE contains the JVM
  • Therefore: JDK → JRE → JVM

Development and Execution Process 🚀

  1. Writing the source code (.java) using the JDK
  2. Compiling (javac) the code into bytecode (.class)
  3. JRE is responsible for loading the necessary classes
  4. The JVM executes the bytecode, translating it into native operating system instructions


Practical Example 💻

Article content

📘 Compiling and executing with the JDK

$ javac Example.java // Uses the JDK compiler to generate Example.class 
$ java Example // Uses the JRE (contained in the JDK) to execute        

⚠️ Executing only with the JRE

$ java Example // Works if Example.class already exists 

$ javac Example.java // Error: javac not available in the JRE        

Java Today: Relevance in the Current Market 🌐

Even after more than 25 years since its creation, Java continues to be one of the most widely used languages in enterprise environments. It's fundamental in banking systems, e-commerce applications, and now in the cloud era with frameworks like Spring Boot and platforms like Jakarta EE.

The JVM has also become an ecosystem that supports dozens of other languages, such as Kotlin, Scala, Groovy, and Clojure, which leverage all the infrastructure of the Java environment to offer different programming paradigms.

In microservices and cloud computing environments, Java has evolved significantly with projects like GraalVM that enable native compilation, reducing memory consumption and startup time - areas traditionally considered weak points of Java.



Which aspect of the Java architecture do you consider most important for the success and longevity of the language?

Do you work with Java or another language that runs on the JVM? Share your experience in the comments! 💬

ABDULQADIR ALDHALIA

"Computer Science Graduate | Microservices & Desktop & Web Developer | Robotics Programming Team Leader | ICPC Competitor | Linux Lover"

3mo

Thanks for the great explanation! 💫 I have a question that's not directly related to the post but is quite important to me. I'm currently working on a cross-platform desktop application using JavaFX, and I'm planning to use GraalVM to compile it into a native executable for each platform. However, I'm not sure how stable GraalVM is with JavaFX—especially when using Java 21 and above. Has anyone here tried this combination before? I'd really appreciate any insights or experiences regarding potential issues or limitations I should be aware of.

Like
Reply
Eduardo Kohn

Fullstack Developer | Java | Spring Boot | React | Angular

4mo

Great article! 🚀 Java's ability to run on over 3 billion devices truly shows its versatility! The JVM's "Write Once, Run Anywhere" philosophy is key to its success. I work with Java daily, and its cross-platform support makes development so much smoother!

Thiago Daudt

Java Software Engineer | Spring | API | Microservices | React | Azure | AWS

4mo

Absolutely fascinating breakdown of the Java ecosystem! It's incredible how the JVM has evolved to support not just Java, but also a variety of other languages like Kotlin and Scala, making it a versatile platform for modern development. One aspect worth highlighting is the role of Just-In-Time (JIT) compilation within the JVM, which optimizes bytecode execution by translating it into native machine code at runtime, significantly boosting performance. Additionally, the advent of GraalVM is pushing the boundaries even further by offering a polyglot runtime that supports multiple languages with high efficiency. Java's robustness and adaptability continue to make it a cornerstone in the ever-evolving landscape of software development. Looking forward to exploring more about how these advancements are shaping the future of programming!

Like
Reply
Priyank Kumawat

Java | Spring Boot | Angular | DSA | Leetcode 500+ | Software Engineer @GeHealthcare

4mo

Thanks for sharing information, Max Benin, it's quite helpful

Like
Reply
Cassio Menezes

Fullstack Software Engineer | Fullstack Software Developer | Java | Spring | Angular | Azure | AWS

4mo

Great to see this discussed.

Like
Reply

To view or add a comment, sign in

Others also viewed

Explore topics