It is very important to understand what is JDK, JRE and JVM in Java.
In this chapter we will have a brief discussion about these terms.
There are two principal products in the Java SE platform family: Java SE Runtime Environment (JRE) and Java Development Kit (JDK).
Java Development Kit (JDK) is which provides the environment to Develop and execute(run ) the Java program.
JDK contains two parts.
1. One part contains the utilities like javac, debugger, jar which helps in compiling the source code ( .java files) into byte code ( .class files) and debug the programs.
2. The other part is the JRE, which contains the utilities like java which help in running/executing the byte code.
You need JDK, if at all you want to write your own programs, and to compile them. For running java programs, JRE is sufficient.
The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine( JVM ), and other components to only run ( not develop ) applets and applications written in the Java programming language.
A Java virtual machine ( JVM ) is an abstract computing machine that enables a computer to run a Java program.
JVMs are available for many hardware and software (i.e. JVM is platform dependent).
JVM (Java Virtual Machine) is a software. It is a specification that provides runtime environment in which java bytecode can be executed. It is not physically exists.
There are three notions of the JVM:1. Specification :The specification is a document that formally describes what is required of a JVM implementation. Having a single specification ensures all implementations are interoperable.
2. Implementation : A JVM implementation is a computer program that meets the requirements of the JVM specification.
3. Instance : An instance of a JVM is an implementation running in a process that executes a computer program compiled into Java bytecode.
As shown in the architecture diagram of JVM, is divided into three main subsystems
1. Class Loader Subsystem
2. Runtime Data Area
3. Execution Engine
1.1. Loading: finds and imports the binary data for a type
1.2. Linking: performs verification, preparation, and (optionally) resolution
1.3. Initialization: invokes Java code that initializes class variables to their proper starting values.
In general, there are two types of class loader: bootstrap class loader and user defined class loader.
Every Java virtual machine implementation must have a bootstrap class loader, capable of loading trusted classes.
Runtime Data Area is divided into 5 major components
2.1 Method Area – All the Class level data will be stored here including static variables. Method Area is one per JVM and it is a shared resource.
2.2 Heap Area – All the Objects and its corresponding instance variables and arrays will be stored here. Heap Area is also one per JVM since Method area and Heap area shares memory for multiple threads the data stored is not thread safe.
2.3 Stack Area – For every thread, a separate runtime stack will be created. For every method call, one entry will be made in the stack memory which is called as Stack Frame. All local variables will be created in the stack memory. Stack area is thread safe since it is not a shared resource. Stack Frame is divided into three sub-entities such as
2.3.1. Local Variable Array – Related to the method how many local variables are involved and the corresponding values will be stored here.
2.3.2. Operand stack – If any intermediate operation is required to perform, operand stack act as runtime workspace to perform the operation.
2.3.3. Frame data – All symbols corresponding to the method is stored here. In the case of any exception, the catch block information will be maintained in the frame data.
2.4 PC Registers – Each thread will have separate PC Registers, to hold address of current executing instruction once the instruction is executed the PC register will be updated with the next instruction
2.5 Native Method stacks – Native Method Stack holds native method information. For every thread, separate native method stack will be created.
The bytecode which is assigned to the Runtime Data Area will be executed by the Execution Engine.
It contains :
1. A virtual processor
2. Interpreter: Read bytecode stream then execute the instructions.
3. JIT Compiler :It is used to improve the performance.JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.Here the term ?compiler? refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU.