×

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

Catalan number in Java

In general mathematics, Catalan numbers can be defined as the sequence of natural numbers that frequently occur in counting problems often encountered in recursively defined objects. Mathematical formula of Catalan number Coming...

3 minutes read.

This Operator Using in Java

this keyword in Java has a wide range of applications. this reference variable in Programming language refers to the object of interest. This keyword is used in Java. this keyword is...

5 minutes read.

ArrayList Program in Java

ArrayList Program in Java: In Java, ArrayList is a class that belongs to java.util package. It is the dynamic list that grows or shrinks at run-time as per the requirements....

4 minutes read.

Swing Program in Java

Java Swing is part of Java Foundation Classes (JFC). The swing toolkit is used to generate Graphical User Interface (GUI) for programs written in Java. The Java swing API is...

4 minutes read.

Ordinal Number in Java

What is the Ordinal Number in Java? An object's or person's position or rank can be expressed mathematically using an ordinal number. Depending on the criteria used to establish the positions,...

3 minutes read.

Zebra Puzzle Problem in Java

Complex puzzles like the zebra puzzle demand a lot of work and mental training to complete. Because it was created by renowned German scientist Albert Einstein, it is also sometimes...

10 minutes read.

Find next greater number with same set of digits in Java

It contains a number (num). Finding the smallest number that has the same number of elements as num that is also larger than num is the task at hand. If...

8 minutes read.

Difference between Abstract Class and Interface

There is a similarity between abstract class and interface is that we cannot create objects for both of them. But irrespective of this, there are some differences between them, let’s...

2 minutes read.

public static void main string args meaning in java

In java main() method is the initial point for execution of the program. If a program doesn’t contain the main method, the program will not execute. JVM(java virtual machine) starts...

3 minutes read.

Race Condition in Java

Java is a multi-threaded programming language, race conditions are more likely to arise. Mostly because data can change when multiple threads visit the same resource simultaneously. Race conditions are concurrency...

3 minutes read.

Java Math toDegrees() Method

The toDegrees() method of Java Math class converts a radian angle to an approximately equivalent angle measured in degrees. Syntax: public static double toDegrees(double angrad) Parameters: The parameter ‘angrad ‘represents an angle measured in...

2 minutes read.

Java Math sinh() Method

The sinh() method of Java Math class returns the hyperbolic sine of the specified double value. Syntax: public static double sinh(double x) Parameters: The parameter ‘a’ represents the number whose hyperbolic sine is to...

2 minutes read.

POJO in Java

Plain old Java Object, in short, is called POJO in Java. POJO is an everyday object that is not subject to any specific limitations. We can use POJO in any Java...

3 minutes read.

Java Generate UUID

What java Generate UUID? A 128-bit long value that is universally unique serves as the basis for the terms UUID (Universally Unique Identifier) and GUID (Globally Unique Identifier). Hexadecimal (octet) digits...

5 minutes read.

IdentityHashMap in Java

The IdentityHashMap class is comparable to the HashMap class and is an AbstractMap implementation. However, when comparing the key, it uses reference equality rather than object equality (or values). Identity HashMap...

6 minutes read.

Program to Implement FLAMES Game in Java

Friends, Lovers, Affectionate, Marriage, Enemies, and Sibling are all represented by the acronym FLAMES, which also serves as the name of a well-known game. Although, it can be entertaining to...

4 minutes read.

Read the XLSX file in Java

Excel files contain cells; reading an excel file in Java differs from reading a word file. JDK doesn't have a direct API that can read or write Word or Excel...

3 minutes read.

Stable Marriage Problem in Java

Given N men and N women, the Stable Marriage Problem asks you to match up the men and women in such a way that there are never any two people...

6 minutes read.

Program to Find Square Root of a Number Without sqrt Method in Java

The Java Math class sqrt () function can be used to determine the square root of a number. In this section, we'll write a Java program to find a number's...

3 minutes read.

Java Destructors

Before knowing about Java destructors, let us know about constructors. If we understand the concept of the constructor, we can easily understand about destructor and also, we will get an...

3 minutes read.