×

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

Gregorian Calendar Java Current Date

GregorianCalendar class uses the Gregorian and Julian calendars. Dates are calculated by projecting present laws forever backward and forward in time. As a consequence, GregorianCalendar may be utilised to create...

8 minutes read.

Binary Search Java

Binary search is a search mechanism for key elements from the given List/Array. In Binary search, the search mechanism is followed by dividing the array into parts; hence the search...

3 minutes read.

Java String indexOf() method

Java String indexOf() method returns index of a given character or substring present in a String. Methods Description int indexOf(int ch)     It returns index position for the given char value.int indexOf(int ch,...

2 minutes read.

How to Reverse a String in Java

How to Reverse a String in Java There are a lot of ways to reverse a string in Java. One can use iteration, StringBuilder, StringBuffer to do the reverse of a...

6 minutes read.

How to compare characters in Java

In this tutorial, we will learn about how to compare characters in Java. To compare characters in Java, we will learn about what is a character in Java Char The character is...

4 minutes read.

Checked vs Unchecked Exceptions in Java

In this tutorial, we will discuss Java's checked and unchecked Exceptions. Exception An exception is an undesirable event that disrupts the normal flow of the program. An exception is thrown at runtime. It...

4 minutes read.

GCD Program in Java

GCD Program in Java The GCD program in Java outputs the GCD of the given numbers. In mathematics, Greatest Common Divisor (GCD), Greatest Common Factor or Highest Common Factor (HCF) of...

14 minutes read.

How to convert list to String in Java

Sometimes, we need to transform a listing of characters into a string. A string is a chain of characters, so we will make a string from an individual array without...

4 minutes read.

Java String hashCode() method

Java String hashCode() method returns hash code for current String. hash code for string object is computed as s[0]*31^(n - 1) + s[1]*31^(n - 2) + ... + s[n - 1] Using int...

2 minutes read.

Composition in Java

Composition Java uses the composition method to implement a has-a connection. Composition allows us to reuse code in the same way that Java inheritance does. The "is-a" relationship is implemented using the...

3 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.

Java Font

The font is a Java class that is a part of java.awt package. The Serializable interface is implemented by it. The direct recognized child of a Java Font class is...

8 minutes read.

How to take String Input in Java

There are various ways to take String input in Java. In this section, we are going to discuss how to take String input in Java. There are following ways to...

5 minutes read.

Java File Extension

A computer file's suffix is called its file extension. It is easily recognized since it appears immediately after a period (.) in the file name. Consider the file Demo.java as an...

3 minutes read.

Bottom view of a binary tree in Java

The lowest nodes in their horizontal distance are present and referred to as the bottom view of a binary tree. The horizontal distance between the nodes of a binary tree...

4 minutes read.

Thread Scheduler in java

Scheduling: it is defined as the execution of multiple threads on a single CPU in some order is called scheduling. Preemptive-priority scheduling: This algorithm schedules threads based on their priority relative to other...

11 minutes read.

Various operations on HashSet in Java

In this article, you will be acknowledged about what is a HashSet in java and what are its operations in java programming language. The HashSet is a crucial part of...

3 minutes read.

Activity selection problem in Java

The activity selection problem is a multiple objective problem hat requires choosing non-conflicting tasks to complete within a specific amount of time from a list of tasks identified by a...

5 minutes read.

Java Thread class

Thread class The thread represents a part of the process. Every process can have multiple associated threads in which every thread may execute the same or different job. By default, each thread assigns...

16 minutes read.

LCM Program in Java

LCM Program in Java The LCM program in Java outputs the LCM of the given numbers. In Arithmetic, the lowest common multiple, least common multiple or smallest common multiple of the...

6 minutes read.