Professional Documents
Culture Documents
*/
Binary code (0s and 1s) or executable codes (exe files) understand by system
directly, byte code is understood by JVM only and this special to java.
If a java program compiles successfully, without getting any errors, then it
creates .class file with same of source file (.java file)
Java supports two types of environments 1. Compile time 2. Runtime
In the compile time environment, java compiler coverts source file to byte code
instructions (.class file) after compilation we will get .class file containing byte
code. In the run time environment, byte code is given to JVM and JVM loads and
executes .class file and passes the result to hardware along with OS instructions.
After runtime environment output of the program will be displayed.
Q: What is JVM (Java Virtual Machine)?
Java virtual machine is hart of entire java program execution process. Its
responsibility is taking .class file and converting each byte code instructions into
the machine language instructions that can be executed by microprocessor
First of all .java program is converted into .class file consisting of byte code
instructions by the java compiler. Now this .class file is given to JVM, in JVM there
is a module (program) called class loader sub system which performs the
following actions
I.
II.
III.
IV.
V.
VI.
1. Class loader sub system: JVM's class loader sub system performs 3 tasks
a. It loads .class file into memory.
b. It verifies byte code instructions.
c. It allots memory required for the program.
2. Run time data area: This is the memory resource used by JVM and it is
divided into 5 parts
a. Method area: Method area stores class code and method code.
b. Heap: Objects are created on heap.
c. Java stacks: Java stacks are the places where the Java methods are
executed. A Java stack contains frames. On each frame, a separate method is
executed.
d. Program counter registers: The program counter registers store
memory address of the instruction to be executed by the microprocessor.
e. Native method stacks: The native method stacks are places where
native methods (for example, C language programs) are executed. Native
method is a function, which is written in another language other than Java.
3. Native method interface: Native method interface is a program that
connects native methods libraries (C header files) with JVM for executing native
methods.
4. Native method library: holds the native libraries information.
5. Execution engine: Execution engine contains interpreter and JIT compiler,
which covert byte code into machine code. JVM uses optimization technique to
decide which part to be interpreted and which part to be used with JIT compiler.
The Hotspot represent the block of code executed by JIT compiler.
1. A virtual processor
2. Interpreter: Read byte code stream then execute the instructions.
3. Just-In-Time (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.
Verifies code
Executes code