Java development is dependent on three things-

  • JDK
  • JRE
  • JVM

Here is the answer to the question- What they are and Why they are necessary?

What is JDK?

JDK refers to “Java Development Kit”. It is a software development environment that contains a set of command-line programs and large number of text-based development tools. They all are used for developing and executing Java applications and applets. Programmers run each of the JDK’s utilities by typing commands at a prompt.

Most commonly used tools are:

  • javac (a compiler)
  • java (an interpreter/loader)
  • jar (an archiver)
  • javadoc (a documentation generator)
  • appletviewer (to run and debug the applets) etc.

For example: java is used on the command line as follows:

java NewPrg.class

This command tells the java bytecode interpreter to run a bytecode file called NewPrg.class.

So one can say that JDK = JRE + Development Tools.

What is JRE?

JRE refers to “Java Runtime Environment”. It is an installation package which provides the minimum requirements for execution (not development) of a Java application or program. As JRE does not contain development tools like a compiler and a debugger, it is used by those who want to only run the Java programs i.e. end users.

Some of its components are as follows:

  • Development Tools
  • User interface toolkits like Abstract Window Toolkit (AWT), Swing, Print service etc.
  • Integration libraries like Java Database Connectivity (JDBC), Remote Method Invocation (RMI) etc.
  • Class libraries
  • Java Virtual Machine (JVM)

So, one can say that JRE = JVM + Library Classes.

What is JVM?

JVM refers to Java Virtual Machine. It is an important part of both JDK and JRE as it is inbuilt in both. Sometimes JIT or Just-In-Time compilers are part of JVM to speed up the execution time. It resides in the real machine (your computer) and enables your computer to run a program (written in Java or any other language) which is compiled to Java bytecode. It does so by converting the bytecode to machine language.

Bytecode is an OOP code which is compiled to run on a virtual machine (VM) instead of directly on a CPU. As for any JVM, it is not possible to understand the Java source code. Here we need a javac compiler that compiles the .java files to obtain .class files comprised of bytecode. The primary function of JVM is to execute the bytecode generated by the compiler.

Bytecodes call various classes provided in the JRE when any action needs to be performed which they cannot do by themselves. Bytecodes lack functionality in them and need the JVM to do many tasks for them.

Each operating system has a different JVM. It produces the same output after the execution of the bytecode across several different operating systems. Which means that a bytecode produced on Mac OS can run on Windows and vice versa. Hence, JVM makes Java portable (write once and run anywhere).

When an application and various underlying platforms communicate with each other, this communication can be very complex and JVM handles it very well by providing a layer of abstraction between the two. Therefore, Java is called a platform independent language.