JAVA TERMINOLOGIES – JVM, JRE AND JDK

In our previous Java programming tutorial, we covered introduce Java programming language.

In today’s tutorial, we will get familiar with common java terms before going deeper into the core java topics.

Java Virtual Machine (JVM)

This is generally referred as JVM. Before, we discuss about JVM lets see the phases of program execution.

Phases of program execution

The phases of program execution are as follows: we write the program, then we compile the program and at last we run the program.

1. Writing of the program is of course done by java programmer like you and me.

2. Compilation of program is done by javac compiler, javac is the primary java compiler included in java development kit (JDK).

It takes java program as input and generates java bytecode as output.

3. In third phase, JVM executes the bytecode generated by compiler. This is called program run phase.

So, now that we understood that the primary function of JVM is to execute the bytecode produced by compiler.

Each operating system has different JVM, however the output they produce after execution of bytecode is same across all operating systems.

That is why we call java as platform independent language.

Bytecode

As discussed above, JDK javac compiler compiles the java source code into bytecode so that it can be executed by JVM.

The bytecode is saved in a .class file by compiler.

Java Development Kit(JDK)

While explaining JVM and bytecode, I have used the term JDK. Let’s discuss about it.

As the name suggests this is complete java development kit that includes JRE (Java Runtime Environment), compilers and various tools like JavaDoc, Java debugger etc.

In order to create, compile and run Java program you would need JDK installed on your computer.

Java Runtime Environment(JRE)

JRE is a part of JDK which means that JDK includes JRE.

When you have JRE installed on your system, you can run a java program however you won’t be able to compile it.

JRE includes JVM, browser plugins and applets support. When you only need to run a java program on your computer, you would only need JRE.

These are the basic java terms that confuses beginners in java. For complete java glossary refer this link:

Main Features of JAVA

Java is a platform independent language

Compiler(javac) converts source code (.java file) to the byte code(.class file).

As mentioned above, JVM executes the bytecode produced by compiler.

This byte code can run on any platform such as Windows, Linux, Mac OS etc.

Which means a program that is compiled on windows can run on Linux and vice-versa.

Each operating system has different JVM, however the output they produce after execution of bytecode is same across all operating systems.

That is why java is regarded as platform independent language.

Java is an Object Oriented language

Object oriented programming is a way of organizing programs as collection of objects, each of which represents an instance of a class.

4 main concepts of Object Oriented programming are:

  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism

Simple

Java is considered as one of simple language because it does not have complex features like Operator overloading, Multiple inheritance, pointers and Explicit memory allocation.

Robust Language

Robust means reliable. Java programming language is developed in a way that puts a lot of emphasis on early checking for possible errors.

That is why java compiler is able to detect errors that are not easy to detect in other programming languages.

The main features of java that makes it robust are garbage collection, Exception Handling and memory allocation.

Secure

We don’t have pointers and we cannot access out of bound arrays (you get ArrayIndexOutOfBoundsException if you try to do so) in java.

That’s why several security flaws like stack corruption or buffer overflow is impossible to exploit in Java.

Java is distributed

Using java programming language we can create distributed applications.

RMI(Remote Method Invocation) and EJB(Enterprise Java Beans) are used for creating distributed applications in java.

In simple words: The java programs can be distributed on more than one systems that are connected to each other using internet connection.

Objects on one JVM (java virtual machine) can execute procedures on a remote JVM.

Multithreading

Java supports multithreading. Multithreading is a Java feature that allows concurrent execution of two or more parts of a program for maximum utilisation of CPU.

Portable

As discussed above, java code that is written on one machine can run on another machine.

The platform independent byte code can be carried to any platform for execution that makes java code portable.

Java is a high level programming language. A program written in high level language cannot be run on any machine directly.

First, it needs to be translated into that particular machine language.

The javac compiler does this thing, it takes java program (.java file containing source code) and translates it into machine code (referred as byte code or .class file).

Java Virtual Machine (JVM) is a virtual machine that resides in the real machine (your computer) and the machine language for JVM is byte code.

This makes it easier for compiler as it has to generate byte code for JVM rather than different machine code for each type of machine.

JVM executes the byte code generated by compiler and produce output. JVM is the one that makes java platform independent.

So, now we understood that the primary function of JVM is to execute the byte code produced by compiler.

The Java Virtual machine (JVM) is the virtual machine that runs on actual machine (your computer) and executes Java byte code.

The JVM doesn’t understand Java source code, that’s why we need to have javac compiler that compiles *.java files to obtain *.class files that contain the byte codes understood by the JVM.

JVM makes java portable (write once, run anywhere). 

JVM Architecture

Lets see how JVM works:

Class Loader: The class loader reads the .class file and save the byte code in the method area.

Method Area: There is only one method area in a JVM which is shared among all the classes. This holds the class level information of each .class file.

Heap: Heap is a part of JVM memory where objects are allocated. JVM creates a Class object for each .class file.

Stack: Stack is a also a part of JVM memory but unlike Heap, it is used for storing temporary variables.

PC Registers: This keeps the track of which instruction has been executed and which one is going to be executed. Since instructions are executed by threads, each thread has a separate PC register.

Native Method stack: A native method can access the runtime data areas of the virtual machine.

Native Method interface: It enables java code to call or be called by native applications. Native applications are programs that are specific to the hardware and OS of a system.

Garbage collection: A class instance is explicitly created by the java code and after use it is automatically destroyed by garbage collection for memory management.

JVM Vs JRE Vs JDK

JRE: JRE is the environment within which the java virtual machine runs.

JRE contains Java virtual Machine(JVM), class libraries, and other files excluding development tools such as compiler and debugger.


Which means you can run the code in JRE but you can’t develop and compile the code in JRE.

JVM: As we discussed above, JVM runs the program by using class, libraries and files provided by JRE.

JDK: JDK is a super-set of JRE, it contains everything that JRE has along with development tools such as compiler, debugger etc.

Now that we have covered Java terminologies, in the next tutorial, we will create our first Java Hello Word program.

Next – First Java Program (Hello word)

Add a Comment