The Implementation Method of Java

Java is a set of computer software and specifications. It provides a system for developing application software in the computing environment. Java initially released in 1966. Java was developed in Sun Microsystems. The first application of Java is called Star Seven. In the present Java becomes more popular than C and C++. The main reason for that is Java is not platform dependent. Imagine C/C++ code written in Windows. That code can’t compile in Linux server. This is platform dependency. This report based on the implementation method of Java. 

The computer can understand some instructions. These instructions are in 1s and 0s. These are called machine instructions. Therefore translation from source code to machine code is done by the compiler. The compiler checks the syntax in our code, optimize our code, and generate the machine code. In compile language machine code is first generated. And then machine code is executed by the CPU. But the interpreter executes the code line by line therefore there is no compilation step. And it is a bit slower but it is platform-independent. In compiled languages, we use machine code. We suppose in machine code there will be a bunch of 1s and 0s. But they are different from machine to machine because every operating system has its architecture. Then machine code generated in two different operating systems for the same program is not similar. 

Java uses both interpretation and compilation. We, programmers, write codes in Java. When we compile the code then code will be converted into Java byte code. In C and C++ the compiler converts the code into machine code but in Java, the Java compiler converts the code into Java byte code. Java byte code is a compiled object code of Java program. In simply we can say the JVM (Java Virtual Machine) can understand the byte code. It means that JVM executes the byte code. After executing the byte code it gives the output. Suppose we create a Java program my_first_code.java after compiling this code the new file is created called my_fisrt_code.class. This .class file is the byte code. And my_first_code.class can execute in any operating system on JVM. So then here we get platform-independent. The compilation is faster that means Java is faster. 

Inside JVM there is a type of compiler instead of an interpreter. We use JIT(Java In Time) compiler to speed up the execution. JVM architecture has 3 major components such as  1) ClassLoader, 2) Run time data area, and 3). Execution engine. 

1)ClassLoader

Java's dynamic class loading functionality is handled by the ClassLoader. It loads links and initializes the class file when it refers to a class for the first time at runtime not compile time.

1)1) Loading

Classes will be loaded by this component and there are three parts and These ClassLoaders will follow Delegation Hierarchy Algorithm while loading the class files.

1) BootStrap – Responsible for loading classes from the bootstrap classpath( rt.jar). The highest priority will be given to this loader.

2) Extension– Responsible for loading classes that are inside the ext folder (jre\lib).

3) Application–Responsible for loading Application Level Classpath path mentioned Environment Variable, etc.


1)2) Linking

1) Verify – The bytecode verifier will verify whether the generated bytecode is proper or not. Then if verification fails we will get the verification error.

2) Prepare – For all static variables memory will be allocated and assigned with default values.

3) Resolve – All symbolic memory references are replaced with the original references from Method Area.

1)3) Initialization

This is the final phase of ClassLoading. All static variables will be assigned with the original values, and the static block will be executed here.

2)Runtime data area

The Runtime data area is divided into five components. 

1) Method area – All the class-level data will be stored here and also including static variables. 

2) Heap area – Here is the place all the Objects and their corresponding instance variables and arrays will store. 

3) Stack area – All local variables will be created in the stack memory and the Stack Frame is divided into three parts. 1) Local Variable Array – How many local variables are involved and the corresponding values will be stored here. 2) Operand stack – This acts as runtime workspace to operate when any intermediate operation is required to perform.3) Frame data – All symbols corresponding to the method are stored here.

4) PC Registers – Hold the address of current executing instruction once the instruction is executed.

5) Native Method stacks –Holds native method information.

3)Execution engine

The Execution engine reads the bytecode and executes it step by step.

1) Interpreter –Interprets the bytecode faster but executes slowly.

2) JIT Compiler – Compiler solve the disadvantage of the interpreter. When it finds repeated code it uses the JIT compiler and it compiles the entire bytecode and changes it to native code.

1) Intermediate code generator – Generate intermediate code

2) Code optimizer – Optimizing the intermediate code generated above

3) Target code generator – Generating machine code or native code

4) Profiler – Finding whether the method is called multiple times or not.

3) Java native interface (JNI) - Interacting with the native method libraries. And it provides the native libraries required for the execution engine.

4) Garbage Collector - Collects and removes unreferenced objects. The garbage collection of the JVM collects the objects that are created.

That is the way of implementation of Java can be presented.


Comments

Popular posts from this blog

Programming Using GNU Octave

Library Problem

What Is A Gamma Ray Burst?