Saturday, December 28, 2019

Java Architecture

Java Architecture

Java is a feature-rich, portable, and object-oriented programming language.

How a Java Program is compiled and executed? 

Java architecture defines that program is compiled by the Java compiler in Java compile-time environment and executed by the JVM (Java Virtual Machine), which is the part of Java Run-time environment

First of all Java code is compiled by the javac compiler and it is converted into bytecodes. Bytecodes are Java's magic. Due to bytecodes, platform in-dependency is achieved by the Java applications. We can move byte codes through the internet or through any other network or we can execute these byte codes on our own local machine using Java Run time environment. It is very important to understand the architecture of Java in this tutorial, we are going to see how a Java program is compiled and executed.

Java Architecture

Step 1:

Create a Java source file with .java extension.

Step 2:

Compile the Java source code using Java compiler(javac) which will create bytecode with .class extension.

Step 3:

ClassLoader reads both the user-defined and library classes into the memory for the execution.

Step 4:

Bytecode verifier validates all the bytecode which are valid and do not violate Java security regulations.

Step 5:

JVM(Java Virtual Machine) reads the byte code and translates into machine code for the execution.
During the execution of the program, the code will interact to operating system and hardware.

What JVM does?

  • JVM first loading the bytecodes from the class files
  • Bytecode verifier verifies the loaded bytecodes for security constraints
  • JVM links the application with the required libraries
  • JVM also performs memory management and Garbage Collection
  • JVM provides the mechanism for managing calls between the application and the host environment.

Java Virtual Machine

  • JVM is an interpreter that converts the bytecode to machine-specific instructions and executes.
  • JVM is platform-specific
  • Most of the modern programming languages are designed to be compiled.
  • The compilation is a one-time exercise and executes faster.
  • It is very difficult to execute compiled code over the internet.
  • Interpreting Java bytecode facilitates its execution over a wide variety of platforms. Only JVM needs to be implemented for each platform.
  • If a machine comprises JVM any java program can be executed on it. JVM differs from platform to platform and is platform-specific.

Video Tutorial