Saturday, February 17, 2024

What Are JVM, JRE And JDK in Java

This post gives a brief explanation of JVM, JRE and JDK in Java. Before going into that explanation you should also know what is bytecode in Java.

What is bytecode in Java

When a Java program is compiled, it is not directly compiled into machine language but into an intermediate code known as bytecode. Bytecode is platform independent and it still needs to be interpreted and executed by the JVM installed on the specific platform.

For example let's say you have a Java file called "Test.java". When you compile this file you get a file called "Test.class" which is the bytecode for your Java file. JVM interprets and executes this Test.class file.

JVM

JVM meaning Java Virtual Machine is an abstract layer between a Java program and the platform that Java Program is running on. JVM is platform dependent and different implementations of JVMs are available for specific platforms.

A Java program can run on a specific platform only when-

  • JVM has been implemented for a platform.
  • JVM has been installed on a platform.

The JVM doesn't understand Java program as we write it, it understands the ".class" file which we get by compiling the .java file. This ".class" file contains the bytecode understandable by the JVM. It is because of JVM that Java is called a "portable language" (write once, run anywhere)

Following figure shows the abstraction provided by JVM by sitting in between the bytecode and the specific platform.

Bytecode interpretation by JVM

JRE

JRE meaning Java Runtime Environment provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language.

The compiled bytecode doesn't run on CPU directly, JVM sits in between and interpret the bytecode into readable machine language for the CPU. It is actually the JRE that enables Java bytecode to run on any platform. Bytecodes, which are interpreted by the JVM, simply call classes found in the JRE when they need to perform actions they cannot do by themselves

JVM and JRE in Java

JDK

JDK meaning Java Development Kit is a superset of the JRE, and contains everything that is in the JRE, plus development tools such as the compilers and debuggers necessary for developing applets and applications.

That's all for this topic What Are JVM, JRE And JDK in Java. If you have any doubt or any suggestions to make please drop a comment. Thanks!

>>>Return to Java Basics Tutorial Page


Related Topics

  1. Why main Method static in Java
  2. Why Class Name And File Name Should be Same in Java
  3. Java Pass by Value or Pass by Reference
  4. static Keyword in Java With Examples
  5. Core Java Basics Interview Questions And Answers

You may also like-

  1. Class in Java
  2. Object in Java
  3. Encapsulation in Java
  4. Constructor Chaining in Java
  5. Fail-Fast Vs Fail-Safe Iterator in Java
  6. Difference Between Comparable and Comparator in Java
  7. Java Semaphore With Examples
  8. Spring Bean Life Cycle

1 comment:

  1. I have read this differentiation on many other websites. But so beautifully and in such a simple manner no one has ever explained. It all seemed very complex to me.

    Thanks for simplifying.

    ReplyDelete