×

Java Architecture

Java architecture is a combination of three parts they are JVM, JRE and JDK. These components will help in the functioning of the java programs. The process of code interpretation and compilation can be done with these components. Java Architecture describes the step-by-step execution and compilation of the code by the java compJava compiler step-by-step execution and compilation.

Java Architecture

The following steps can describe Java Architecture:

  • Java has both compilation and interpretation processes.
  • The compiler in java will convert the written java code to byte code.
  • After converting to byte code, the component( JVM) will convert it to machine code.
  • After that, the converted machine code is executed using the machine.

Now let us discuss the components in detail.

Components of  Java Architecture

  • Java Virtual Machine (JVM)
  • Java Runtime Environment (JRE)
  • Java Development Kit (JDK)
Java Architecture

Java Virtual Machine

Java Virtual machine main feature WORA. Write Once Run Anywhere. This feature describes that you write the code at once and can use the program it any platform or on any platform. What can run the programs written in java on any of the platforms due to the availability of the Java Virtual Machine? Java Virtual Machine will act as a platform for executing java programs. The foremost task of this machine is to convert byte code to machine code. Firstly it will load the code and verifies it in the memory. After loading the code into memory and it executes the code. JVM can be available for any platform because it is platform-independent.

1. It will specify the working of the JVM. Oracle and many other companies can provide the implementation.

2. Implementation can be done by JRE (Java Runtime Environment)

3. The runtime instance in this code is written on a command prompt to run java code.

The operations which JVM performs are:

  • Loading the class
  • Verifying the code
  • Executing the code
  • Provided the runtime environment

JVM Contains:

  • Memory
  • Class file
  • Registering the set
  • Garbage collection heap

It contains the classloader, memory area, and execution engine.

1) Classloader

This system is a subsystem of JVM for loading files. When the java program was running, it loaded in the class loader. There are three classloaders in java.

->Bootstrap ClassLoader: This is the superclass of the Extension. In this class rt.jar

    file is in java.lang package, java.io, and java.sql packages.

->Extension ClassLoader: This is the base class of the classloader of Bootstrap and the parent class of the System classloader. The jar files are loaded inside the $JAVA_HOME/.          

JRE/lib/ext directory.

->Application classLoader: It is the base classloader for the extension class loader. The files loaded in the classpath. Classloader will set it in the classpath. The class can be changed by using the command “ -cp”. As it will switch the application, it is called an Application classloader.

//Program

//Example, for printing the class loader 
public class loader 
{  
    public static void main(String[] args)  
    {  
        // printing the class loader for the current class    
        //classloader will load the class   
        Class c=CLoader.class;  
        System.out.println(c.getClassLoader());  
        //the result will be printed as null because it is a builtin class it can be founded in
        // rt.jar
       
        System.out.println(String.class.getClassLoader());  
    }  
}     

Output:

Java Architecture

2) class Area

This method will store the per-class structures for storing the runtime pool and the code for storing the methods.

3) Heap

The Heap area is used for storing the objects.

4) Stack

The stack area is used for storing frames. The stack area will store the local variables and methods. Threads are created in the stack area for each new thread creation. When the method invocates, it will destroy the frame.

5) PC Register

It is a program counter register containing the address of the JVM that is currently executed.

6) Native Method Stack

can store the native methods used in the application in the Native Method stack.

7) Execution Engine

The execution engine will work as a virtual processor. It contains an Interpreter for reading the byte code, and then the instructions are executed. JIT is a Just-in-Time compiler used for performance improvement. This compiler will compile the code with similar functionality and reduce compile time. The compiler will transform instructions from JVM to CPU instructions set.

8) Java Native Interface

This interface is a framework which provides a platform to relate programs from different languages (C, C++)  to their applications. It is used to get the console output and interact with the operating system libraries.

Java Runtime Environment

It will create an environment for the execution of the program. The process works; the code is first loaded and integrated with the libraries required, and after this process starts, JVM  for running the code. Java Runtime Environment is the Java Development kit(JDK) subgroup. It contains the class libraries and stand-alone JVM. It is one most available environments for executing java programs. Using the JRE, the written code is converted to byte code for executing the byte code JRE required in any platform. JRE will be on top of most of the operating systems.

It contains:

  • Java web start can be done using JRE
  • Interfaces toolkits ex: java 2D
  • It contains the libraries for connecting the Database(JDBC).
  • Predefined libraries such as lang and util.
  • It also includes some libraries like Java Management Extensions (JMX) and java processing libraries.

What does JRE contain?

The components of JRE are:

  •  Deployment technologies the technologies are deployment, plug-in etc.
  • Interface toolkits are for designing applications interfaces, such as Abstract Window Toolkit(AWT), Swings, Applet, Sound and input methods.
  • Libraries Java Data Base Connectivity(JDBC), Java Naming And Directory Interface(JNDI), Remote Method Invocation(RMI).
  • Other libraries include I/O input and output, extension mechanisms, Net Beans, Java Native Interface(JNI), Math module, Overriding mechanism, Serialization method and XML processing in java.
  • Base libraries include the lang, util, Zip files,  Java Archive (JAR) files, Collections, API performances, and Re Expressions(Regular Expressions).
  • Java Virtual Machine will act like a server connecting the Server to the Virtual Machine and client.

Working of JRE with the JVM

Java Architecture

JRE contains Java Virtual Machine inside it, Library classes, and Development tools.

We can understand the working of JRE with the help of the below program.

//Program

import java.util.*  
public static void main(String[] args){  
System. out.println(?Hi Everyone?);  
}  

After completing the program's writing, you can save the program with the .java extension. After saving the program with the java extension, it will be compiled using the javac filename.java. The result is Bytecode, independent of the platform, so it can run in any JRE software. From this, the work of JRE begins. The following diagram describes the flow of byte code:

Java Architecture

The steps which are taken at runtime:

  • Class loader
    In this step, the class loader will load the required classes for running the code. It will load dynamically from JVM. The class loader which is used are:

1. Bootstrap class loader
2. Extensions class loader
3. System class loader

  • Byte code verifier
    It will work as security checking the Bytecode to reduce disturbance for an interpreter. Can do the interpretation of code only once.
  • Interpreter
    An interpreter will read the code line by line by following the functions:

    Execution of the byte code.
    Making calls to hardware.

In the above process, can exe can execute the program in JRE.

Java Development Kit (JDK)

The Java Development kit is an environment to develop software applications and dynamic web pages(Applet). JDK contains JRE and the development tools. Any of the below java platforms can implement JDK by Oracle corporation:

  • Standard Edition
  • Enterprise Edition
  • Micro Edition

JDK contains virtual machines and others like interpreter java, compiler javac, and archiver jar for developing java Applications. There are different kinds of components available in JDK:

Applet viewer:Without having any web browser, the running and debugging of applets can be done by this.
Apt:It is used for processing.
Next check:It is used for the detection of conflicts.
Java:The development and deployment process can be done with a single launcher. Java is used for loading the applications. It is an interpreter which generates class files.
Jmc:It is the mission controller
Jps:It is a java virtual machine process status tool used to instrument the virtual machine's hotspot.
Policy tool:It will create a policies management tool, which is used in determining runtime and other sources.
Wsimport:It is used for invoking web services.
keytool:The use of this tool is for keystores manipulation
TranscriptIt is a command line script
JavainfoThis component's utility is getting the information from the java machine.

Related Topics

Java Instanceof Keyword

To determine whether an object is an instance of the supplied type in Java, use the instanceof operator (class or subclass or interface). The type of comparison in java differentiates the...

4 minutes read.

Java Substring

What is a substring in Java? Here by the name  " substring " itself, we can easily come to know it is a part of a string or a subset of...

4 minutes read.

Java Math nextAfter() Method

The nextAfter() method of Math class returns the floating-point value adjacent to the first argument in direction of the second argument. Syntax: public static double nextAfter (double start, double direction)public static float...

2 minutes read.

How to uninstall the Java in Ubuntu

We need java on our computers in our daily lives because there are lots of different applications that are developed using the java environment, so we have to install java...

4 minutes read.

Java Lock

A lock is indeed a threaded synchronization technique similar to Java's synchronized blocks, however, locking can be more complex. It's not like we can completely get rid of the synchronized...

5 minutes read.

Merge Sort in Java

Merge Sort in Java Merge sort in Java uses the divide and conquer approach to sort the given array/ list. There are three steps involved in the merge sort. 1) Divide the...

5 minutes read.

Enum Java Interview Questions

1. What exactly is Java? Java is a portable, high-level, object-oriented, robust, secure, platform-independent, multi-threaded, high-performance programming language. Developed in June 1991 by James Gosling, also known as Platform. 2. Enum is...

3 minutes read.

How to Create an API in Java?

Introduction The API can be abbreviated as Application Programming Interface. An API is a combination of set of classes and interfaces. It is also equivalent to a simple java program. To...

12 minutes read.

Java RMI

What is RMI in Java? A framework for developing distributed Java applications is provided by the RMI (Remote Method Invocation) API. An object can call methods on an object running in...

4 minutes read.

How to Update Java

As we all know that java can be installed in all operating systems like windows, Linux, macOS. We are available with the java 17 and java 18 versions in the...

3 minutes read.

Java Math multiplyFull() Method

The multiplyFull() method of Math class returns the exact product of the arguments. Syntax: public static long multiplyFull (int x, int y) Parameters: The parameters ‘x’ and ‘y’ represent the first value and second...

1 minute read.

How to Reduce Time Complexity in Java

What is time complexity?  The time complexity in java is given as the amount of time a program requires to run or execute it Calculating the time complexity of the program The time...

4 minutes read.

Prime Number Program in Java

Prime Number Program in Java using for loop A natural number which is greater than 1 and has only two factors the number itself and 1 is called prime number. In...

2 minutes read.

Java Read File Line by line

Java provides two options to read files line by line. Each option offers different benefits and has its own set of drawbacks. Following are the ways through which on accomplish...

5 minutes read.

Compare time in java

Introduction: This article discusses how to compare time in java. Maximum of the time we need to examine the date and datetime items. Date comparisons are vital if you want to...

3 minutes read.

Chromatic Number in Java

The chromatic number is the bare minimum of colours necessary to accurately colour any graph. To put it another way, the chromatic number can be thought of as the bare...

6 minutes read.

Null Pointer Exception in Java

It is a runtime error exception. The null value is allocated to the object reference in this exception. We will explicitly throw this null pointer exception when the program wants...

3 minutes read.

Applet Program in Java

Applet Program in Java An applet is a program that can be embedded in a web page. Applets programs are run by a web browser. It mainly works on the client-side....

3 minutes read.

How to Convert Decimal to Hexadecimal in Java

How to Convert Decimal to Hexadecimal in Java The hexadecimal number uses 16 values to represent a number. Numbers from 0 to 9 represented by digits and the numbers from 10...

3 minutes read.

Model Class in Java

In this section, we will be acknowledged about the model class in Java, its purpose and its uses. Also, we will learn how is this created and leveraged in java. Model...

4 minutes read.