Object Oriented Programming Advanced Java Programming

JDK, JVM and JRE: java program internal

Java is an object-oriented programming language. Which is based on the concept of objects and classes. Java considers everything in this world is an object. And the group of related objects known as classes. In OOP everything is write in terms of classes and objects. Java is famous for its platform independent feature. The same code written in java can be executes on multiple platforms. First of all, we should understand the concept of how a java file is complied and run before we understand java program internal in java. So, lets understand java program internal by understanding the diagram below.

java program internal
Fig: Process of Compilation and Interpretation in JAVA

In the above diagram, we can see the process of compilation and interpretation of a Java program. We can see that, there are different terms like source code, byte code, machine code, compilation and interpretation. Lets understand these terms in detail.

Source code

Source code is something that is on the .java file. When programmer write some code, it considered as source code before compilation. The source code contains different variables, methods, constructors, classes, interfaces and blocks of codes. The source code is write in the human readable format.

Compilation

The compiler coverts the source code into byte code. The process of conversion is compilation. The JAVA compiler plays important role during compilation. Furthermore, Java code cannot undergo compilation without a compiler. Moreover, this environment is referred to as the compile-time environment.

Byte code

The output of compilation process is byte code. Byte code is code that is in the machine understandable form. Human can not understand the byte code. It consist ascii values due to which human can not read it. Moreover, the byte code is ready to interpret by the JVM. Additionally, the Java compiler converts the .java file into .class format when it performs the compilation to generate bytecode.

Interpretation

As Compilation occurs as compile time environment likewise, Interpretation occurs as runtime environment. During runtime environment, different components works on the byte code. Firstly, the class file (.class) will be loaded by class loader which is component of JVM (Java virtual machine). Secondly, the byte code is verified to ensure that there is no any illegals access to the objects. And finally, the interpreter interprets the code line by line to execute instructions that communicate with the hardware.

So, lets understands the roles and responsibility of JVM, JRE and JDK one by one.

Java program internal

In the above figure, there is design of JVM vs JDK vs JRE on the device RAM. There is JDK (Java development kit) on the RAM. The JRE and JVM will be automatically installs when user install JDK in the device. So, we can say that JVM and JRE comes under the JDK.

JDK

JDK stands for java development kits. It is an environment for developing java applications. It includes different tools and libraries to develop and test the java program. If a developers wants to compile the java code they needs JDK. Additionally, JDK is also require to build JARs file to deploy the program in the server. We can simply understand the JDK = JRE+JVM.

JRE

JRE stands for java runtime environment. The JRE provides runtime environment for the java programs. It provides different external files and libraries tot he java program during runtime. So, during runtime JRE is necessary.

JVM

JVM stands for java virtual machine. JVM plays important role in converting byte code into machine code. JVM interprets the byte code line by line and execute. The class file (byte code) is loads in the class loader. The class loads helps to load the byte code with the help of external libraries and files provided by the JRE. Moreover, the byte code is verify by the byte code verifier in order find out any illegal access of objects in the byte code. Then the execution engine executes the verified byte code and converts into the machine code. And machine code is understandable to the hardware.

About Author

Pratiksha Shrestha