JDK is JAVA Development Kit. This Kit contains different software utilities(tools) to compile and execute JAVA program.
Below is a diagram of components inside a JDK:
JDK has two main components as seen from above diagram:
JVM(Java Virtual Machine) which is the main component of JRE(Java Runtime Environment).
Development Tools viz. javac - Java Compiler
Let us understand the working of JDK :
We have a java program P1.java To execute P1 we will follow below instructions on the Terminal:
//invoke Java comiler to compiler P1. javac command will invoke the JAVA compiler
//inside the JDK
javac P1.java
//On succesful compilation of P1.java,Compiler produces a .class file //We will have a P1.class created by Compiler
//execute P1 program
java P1
//java command above will invoke JRE inside JDK
//JRE will take the P1.class and execute it on the JDK
//to produce the output of P1 program
What is a .class file?
.class file is the intermediate file created on successful compilation of a JAVA program. It is also called as bytecode.
It is an intermediate code which can be interpreted by a machine like a JVM.
Why does JAVA create a .class file?
The .class or bytecode file is the reason why JAVA is a platform independent language. A bytecode can be taken and executed on any machine with any operating system as long as a JDK is available on the executing machine.
For instance,
We have 3 machines:
Machine | Operating System | JDK present |
M1 | Windows | YES |
M2 | Linux | YES |
M3 | MAC | YES |
A program P1.java was compiled and a successful P1.class was generated on M1. As bytecode is platform independent, this P1.class can be executed on M2 , M3 and as well as M1. We need not re-compile P1.java on machines M2 and M3!
Due to this behaviour, JAVA is termed as platform independent language.
It is important to remember that JDK is essential for execution of bytecode. Without JDK, we cannot execute a bytecode or .class file!
Is JAVA a compiled language?
YES! Java is a compile language. As we compile the .java file to produce a compiled .class version which is executed to produce output.
What is the role of Just-In-Time (JIT) compiler inside JRE?
JRE has a component called Execution Engine. This has 3 main tools : Interpreter, JIT and Garbage Collector. The bytecode file is interpreted by the Interpreter line by line to produce the machine level code. But, if there is repetitive code then use of interpreter is time consuming, in such scenarios Execution Engine calls JIT to compile the bytecode and produce machine readable format!
Comments