Home Introduction to JVM
Post
Cancel

Introduction to JVM

The JVM is a vital component of the Java ecosystem, providing a platform-independent environment for executing Java applications. It ensures that Java applications can run on any device that has a JVM installed, making Java one of the most versatile and widely used programming languages in the world.


Contents


What is the JVM?

The JVM is an abstract computing engine that provides an environment where Java bytecode can be executed. It’s part of the Java Runtime Environment (JRE), which also be included in the Java Development Kit (JDK).

JVM, JRE and JDK

The difference between JVM, JRE and JDK:

  1. JVM (Java Virtual Machine):
    • JVM is an integral part of the Java platform and is responsible for executing Java bytecode.
    • It provides a runtime environment in which Java applications can run.
    • JVM translates Java bytecode, which is platform-independent, into native machine code that can be executed by the host operating system.
    • JVM also manages memory, garbage collection, and provides various runtime services to Java applications.
    • It ensures the “Write Once, Run Anywhere” capability of Java by abstracting the underlying hardware and operating system.
  2. JRE (Java Runtime Environment):
    • JRE is a subset of the JDK and is primarily meant for running Java applications.
    • It includes the JVM, Java core libraries (API classes and methods), and other runtime components required for running Java applications.
    • Developers who only need to run Java applications can install JRE on their systems without the need for JDK.
    • JRE does not include development tools like compilers and debuggers.
  3. JDK (Java Development Kit):
    • JDK is a comprehensive development environment for Java applications.
    • It includes JRE, the Java compiler (javac), debugging tools, and various utilities and libraries for developing Java applications.
    • JDK is used by Java developers to write, compile, debug, and package Java applications.
    • It provides all the necessary tools and resources to create Java programs, including the ability to create executable Java archives (JAR files) and Java applets.

The essence of learning about the JVM is to understand how Java programs are executed and optimised.

How Does the JVM Work?

  1. Loading: The JVM loads the compiled Java bytecode (.class files) into the memory.

  2. Verification: The bytecode is verified to ensure that it adheres to the JVM’s constraints and is safe to execute.

  3. Compilation: The bytecode is compiled into native machine code by the Just-In-Time (JIT) compiler.

  4. Execution: The host machine executes the native machine code.

Components of the JVM

Class Loader

The Class Loader is responsible for loading the compiled Java bytecode into the JVM.

Runtime Data Area

The Java Memory Model defines how the JVM manages memory, including the heap, stack, method area, etc.

Execution Engine

The Execution Engine is responsible for executing the bytecode. It includes Interpreter, Garbage Collector and the Just-In-Time (JIT) compiler, which compiles the bytecode into native machine code. The Garbage Collector is responsible for automatically managing the memory by reclaiming memory that is no longer in use.

This post is licensed under CC BY 4.0 by the author.
ip