What are the components of Java Architecture

Related Courses

Components of Java Architecture

 Through Java Architecture we have the compilation and the interpretation both combined. And the architecture details all the processes executed while we formulate the Java Program. And before we proceed with the article, let's have a brief on what we are going to cover. We are going to cover what Java architecture is, what are the components of Java, why Java is platform-independent, and what is JIT in Java. And you can contact us for your Java training. Naresh I Technologies is the number one computer training institute in Hyderabad and among the top five computer training institutes in India. Contact us anytime for your Java training. 

So, what is the Java Architecture?

It’s the compilation and interpretation joined together. We write the code in Java, convert it into Byte code, and it is done by Java Compiler. The JVM converts the byte code to the machine code. The machine code is platform-independent, and its executed by the machine. However, the JDK must be installed on the machine. Post Java 10, the JRE is included within the JDK. And you will not find the JRE separately now. And the JVM is included in the JRE. 

Hence, the javac compiles the source code, which we write in Java in the IDE or any editor. Now the javac generates the .class file. And this class file is the byte code. The bytecode is the set of instructions to the JVM. The JVM is the part of JRE, and it contains both the compiler and the interpreter. The interpreter interprets the byte code into machine code, and the CPU can then execute the machine code for the final output. 

Remember,

  1. The interpreter is the part of the JVM, and JVM is machine-independent. However, JRE is machine-dependent. Also, the JDK is machine-dependent. Now the JRE is included in JDK since post-Java 10. JVM is part of JRE. And JVM is machine-independent.

  2. Hence, Java is platform-independent because of the JVM and not because of JRE or JDK.  And that is why we say Java supports the WORA. 

Also, remember:

  1. The bytecode contains the .class file for each class separately. 

  2. The .exe files of C++/C can be executed directly, and hence are not secure. However, the .class files or the bytecode cannot be executed directly, and hence Java is secure.

  3. The .exe files of C++/C are platform-dependent, and the .class files or the bytecode are platform-independent. 

  4. Also, the .exe files cannot be converted back to source code. However, the bytecode can be converted back to the source code.

Let’s have a look at the java architecture more deeply, and let’s look at the components of Java.

Various components of the Java Architecture

We have three components of the Java language: JRE, JVM, and JDK. And we already know their full form by now, and hence I am not including it here. However, we are going to discuss them deeply one by one below.

Java Virtual Machine

The Java applications support the WORA as we can run the Java code on any platform.  And this is due to the JVM. It’s the component of Java that caters to us an environment for Java program execution. The JVM has an interpreter that interprets the bytecode into machine code. And this is executed in the machine where the Java program runs.

And in a nutshell, the JVM does the following functions: It loads the code, does the verification of the code, executes it, and provides the runtime environment.

Now, let's have a look at the JVM architecture now. The classes are loaded by the Classloader into the JVM memory, which has four parts, the method area, the stack, the heap, and the native stack. The execution engine is formed of the JIT compiler and the Garbage collector, there is a native interface that acts as the interface between the JVM memory, execution engine, and the native libraries.

Explanation:

ClassLoader: The Classloader happens to be the subsystem of the JVM. Java uses it to load the .class files. And when we run the Java program, the class files are loaded first. 

Class Method area: This is the Data Area in the JVM, and the class data is stored there. The static variables, static methods, static blocks, and instance methods are being stored here.

Heap: This is made when the JVM starts. And it can decrease as well as increase in size while the application runs.

Stack: The JVM stack is the thread stack. This is the data area in the JVM memory made for a single execution thread. This is used by the thread for storing various elements like partial results, local variables, and the data for invoking the method and returns.

Native stack: This subsumes all of the native methods in the application.

Execution Engine:

  • JIT compiler

  • Garbage collector

JIT compiler: The JIT is a section of the runtime environment. And it betters the performance of the Java applications as it compiles the bytecode into machine code at run time. By default, it is enabled. And when we compile a method, the JVM directly fetches the compiled code of the method. The JIT compiler compiles the bytecode into machine code and compiles it JIT for running.

Garbage collector: It is used for collecting unused content. It’s a part of JVM. And it keeps a record of each object in the JVM, and it removes all that is unwanted. It follows two steps for working, which are Mark and Sweep.

Mark: This is where the garbage collector finds which memory is in use and which is not in use.

Sweep: This removes the object which is found during the Mark stage.

Java Runtime Environment:

The JRE software develops the runtime environment, where the Java programs can be executed. It is the on-disk system that picks the Java code, combines it with all the libraries required, and then finally JVM executes it.  The JVM has all the libraries as well as the software required for running the Java program. It is a part of the JDK; however, it can be downloaded separately also.

JDK or the Java Development Kit:

This is the software development environment that is made use of for developing the applets and the Java Applications. It has the JRE and various development tools, like loader/interpreter, archiver like a jar, javac (compiler), a document generator like Javadoc, as well as various other tools. 

So the JDK means JRE + development tools. And the JRE means JVM + library files. 

java: This is the launcher of the java application.

javac: this compiles the Java source code.

javadoc: This generates the API documentation.

jar: This creates as well as manages the JAR files.

And we can now have a look because Java is platform-independent.

So how the Java is Platform Independent?

A programming language that runs on all the operating systems when we talk of the development and compilation.

And Java is platform-independent due to the bytecode, and we have already discussed this. However, let's repeat what it is. It is the code instruction to the JVM which is machine-independent.

Below, we are briefing the complete step again in detail. The source code is compiled, and the javac generates the Bytecode, and the JIT compiler in JVM converts the bytecode into native machine code at run time.

Hence java source code or .java ? javac (.class), JVM (sample.obj) ? final output.

Hence, the source code is converted into a .class file by the java compiler. And the .class file is converted to the byte code by the javac. The JVM converts it to the object file. And that is seen as the final output, which you see over the screen

Now, let's understand the JIT in java.

JIT in Java

This deals with the performance optimization of the Java-based applications at run time.  And the performance depends upon the compiler. And we have already seen the whole process, and how JIT does the magic.

The JIT compiler does the compilation of the byte code and converts it into machine code, and it compiles Just in Time for running. When JVM compiles the method, it calls directly the compiled code of the method.

Let’s have a broader look.

The bytecode requires interpretation or compilation to a well-defined machine instruction which depends upon the instruction set passed. And execution can be direct if the instruction architecture is based on bytecode. The bytecode interpretation takes time, and hence the execution speed gets affected.

For better performance, the JIT compiler does the communication with the JVM at run time and it compiles the appropriate bytecode categorization into a native machine code.   And through the JIT compiler, the hardware executes the native code, and not like JVM interpreting the same bytecode sequence again and again. That can incur overhead on the translation procedure.

And that brings us to the end of this article. Hope you now have the complete detail of the Java architecture. And we will be coming up with more on Java. Hence, do keep reading our blog.

Naresh I Technologies is the number one computer training institute in Hyderabad and among the top five computer training institutes in India. Contact us anytime for your Java training. You can also opt for Java online training, and from any part of the world. And a big package is waiting for you. And all is yours for a nominal fee affordable for all with any range of budget. Let's have a look at what you will get with this Java training package:

  • You need to pay a nominal fee.

  • You can choose any Java certification, as per your skills and interest.

  • You have the option to select from online and classroom training.

  • A chance to study at one of the best Java training institutes in India 

  • We provide Java training in Hyderabad and USA, and no matter in which part of the world you are, you can contact us.

  • Naresh I technologies cater to one of the best Java training in India.

  • And a lot more is waiting for you.

Contact us anytime for your complete Java online training.