In this tutorial, we will be discussing java architecture and its several components. You will master the three important java components - JVM, JRE, and JDK. This includes their working principle and how they differ from each other.
Architecture is a basic plan of all the components that collectively define the system comprising the structure, the interfaces, the modes of communication, etc. The comprehensive architecture of java is the fusion of multiple components . Below shows an outline sketch of java architecture.
The first and foremost component of Java is the Java application which comprises another two components - the java programming file and the java class file. The java class files are the files that get created on the compilation of the Java source file. Here the source code is converted into a machine-independent byte code. These bytecodes are then passed to Java Runtime Environment(JRE) which is yet another important component of java. The byte codes now integrate with the class libraries and the Java Virtual Machine interprets these byte codes and translates them to native machine code. Java, thus, embodies both the techniques of compilation and interpretation.
JVM stands for Java Virtual Machine. As its name suggests, JVM behaves as a virtual processor and is one of the core elements of java. The main objective of this virtual processor is to interpret the byte codes and convert them into native machine code.
The position of JVM in Java Architecture is highly remarkable. As you can see in the above diagram, JVM is a part of JRE and is placed on the top of the operating system. This enables JVM to easily interact with multiple operating systems which makes java so powerful and portable.
Now let's dive deep into the working system of Java Virtual Machine. When you observe the diagram of Java architecture, you can see that the JVM is built of 3 main subsystems.
Class loader subsystem is an inevitable component of Java Virtual Machine. The responsibility of a class loader subsystem is not limited to simply finding and loading class files to memory, despite being pledged for the verification of exactness of the imported class files, for allocation and initialization of memory for class variables, and many more. All these activities are achieved through 3 processes namely
This is the first phase of the classloader subsystem which is obligated to perform two functions. Firstly to find the byte code file requested by the VM for a particular class and secondly to load these bytecodes to the main memory. Class loaders are categorised into three types based on the class type and class path. They are:
BootStrap Loader
This middle phase is responsible for linking the class files with the runtime state of JVM for execution. This phase begins with the process of verification, where the byte code verifier ensures that generated bytecode is proper in the sense it adheres to the semantics of the language and does not disturb the integrity of JVM.
The very next step is a preparation where the JVM allocates memory for all static variables and assigns them with default values observing the variable type.
The linking phase ends with an optional process called resolution where JVM replaces all the symbolic references of classes, interfaces, methods, etc with the concrete references from the Method Area.
As stated in Java 8 Virtual Machine Specification, initialization of a class or interface consists of executing its class or interface initialization method.
On reaching this final phase of class loading the class is ready for its active participation in the application. Initialization involves two main functions
Runtime Data Area or the Memory Area is the second important section of a Java Virtual Machine. The java memory is mainly divided into five parts. These are :
The execution engine is the core part of Java Virtual Machine where the execution of bytes codes takes place. It is this phase that translates human-readable codes into machine language executable codes.
The execution engine consists of three main sub-components. They are:
The JNI is a non-java programming interface that is used in situations where you can’t entirely depend on java for writing your application. At times you may need to incorporate methods or libraries written in other languages like C, C++, etc to run your application. In such cases, you can use this native method interface which allows the java codes that execute inside the JVM to work together with applications and libraries written in other languages. The main advantage of using this JNI framework is the code reusability and high performance.
Java Native Libraries are libraries that contain codes or applications written in non-java languages for instance C, C++, etc. They can be included in the java application as per the requirement with the help of JNI.
JRE stands for Java Runtime Environment. As its name suggests, it is mainly used for running the java code. JRE contains the Java Virtual Machine which we discussed earlier and other browser plugins and tools that support the running of java applets. JRE is one of the important parts of JDK.
JDK, short for Java Development Kit, is a feature-rich software development environment primarily used by java programmers for developing java codes(java applications or applets). It comprises various tools needed for building and executing java codes like
So if you're a novice to JAVA, let's make it clear that to develop a java code in your system, the first and foremost step you need to undergo is to download the JDK into your development environment and establish the path. While downloading you can choose the desired java version and java edition. Java editions are of 3 types:
Don’t bother yourself too much about the installation of java, you will learn it step by step in our next tutorial-JAVA INSTALLATION AND SETUP FOR WINDOWS.
Now let’s sum up everything we have learned so far by comparing the 3 essential components. Below is the best visualization referring to the correlation of JVM, JRE, and JDK.
The difference is listed in the table below:
JDK | JRE | JVM | |
---|---|---|---|
Stands for | Java Development Kit | Java Runtime Environment | Java Virtual Machine |
Is a | software development tool | Software package | Abstract machine |
Used for | Developing applications | Running application | Interpretation |
Dependence | Platform dependent | Platform dependent | Platform independent |
Contains | JRE, JVM, Class libraries, compilers, debuggers, etc | JVM, class libraries | Subset of JDK and JRE |