JVM and Java API
JVM stands for 'Java Virtual Machine'.
The JVM is a virtual machine capable of executing java bytecode.
JVM is used to execute the compiled java programs.
The JVM is distributed along with the set of standard class libraries that implements the
Java Application Programming Interface(API).
API's bundled together with JVM form the JRE(Java Runtime Environment).
The java platform has two componenets :
- JVM
- Java API
It is grouped into libraries of related classes and interfaces, these libraries are known as
packages.
The API and JVM insulates the program from the underlying hardware.
The use of same bytecode for all JVM's on all one platform also allows Java to be described
as "write once, run everywhere".
The following figure shows the concept of platform independence- first compilation of
source file into byte code with the help of JAVAC compiler and excecution of this file
by JVM on different operating systems.
Whenever a Java application starts a runtime instance of JVM is born and when the
application completes it dies.
If three applications are started at the same time, on the same PC, you will get three
JVm instances.
Each application run inside its own JVM.
Internal Architecture of JVM :
Method Area and Heap :
- Each JVM implementation has a heap and method area.
- Heap is shared among all the threads. It is the runtime data area in which all class
instances and arrays is allocated. - Method area is shared among all the threads. It stores per class-structures such
as method data, the code for methods.
- Loading : Load binary representation of class(*.class) .
- Linking:
-Verification : Ensure that the binary representation is structurally valid.
-Preparation :Create the static fields for class and interfaces and initializing those
fields to their standard values.
-Resolution : Determine concrete values from symbolic references in the runtime
constant pool. - Initializing : Invoke its static initializers and the initializers for static fields declared
in class.
- PC(Program Count) register. It contains the address of the java virtual machine
instructions currently being executed. - Each thread has its own PC register.
- If the method currently being executed by the thread is native, then the value of
the java virtual machine's pc register is undefined.
- Java Stack stores frame.
- Each java thread has a private JVM stack, created at the same time as thread.
- Java stack holds local variables and partial results, and plays part in method
invocation and return.
- A virtual processor--the core of JVM.
- Programming aspect : interpreter.
- Read bytecode stream then execute the instructions.
0 comments:
Post a Comment