Simple Simple Simple Simple Program Program Program Program of of of of Java Java Java Java
Simple Simple Simple Simple Program Program Program Program of of of of Java Java Java Java
1. class Simple{
2. public static void main(String args[]){
3. System.out.println("Hello Java");
4. }
5. }
save this file as Simple.java
Bytecode Verifier: checks the code fragments for illegal code that can violate access
right to objects.
------------------------------------------------------------------------------------------------------------------------------------------
JVMs are available for many hardware and software platforms. JVM, JRE and JDK are
platform dependent because configuration of each OS differs. But, Java is platform
independent.
o Loads code
o Verifies code
o Executes code
o Provides runtime environment
JRE
Implementation of JVMs are also actively released by other companies besides Sun Micro
Systems.
JDK
JDK is an acronym for Java Development Kit.It physically exists.It contains JRE +
development tools.
JVM (Java Virtual Machine)
1. Java Virtual Machine
2. Internal Architecture of JVM
JVMs are available for many hardware and software platforms (i.e. JVM is platform
dependent).
What is JVM
It is:
What it does
The JVM performs following operation:
o Loads code
o Verifies code
o Executes code
o Provides runtime environment
o Memory area
o Class file format
o Register set
o Garbage-collected heap
o Fatal error reporting etc.
1) Classloader
2) Class(Method) Area
Class(Method) Area stores per-class structures such as the runtime constant pool, field
and method data, the code for methods.
3) Heap
4) Stack
Java Stack stores frames.It holds local variables and partial results, and plays a part
in method invocation and return.
Each thread has a private JVM stack, created at the same time as thread.
A new frame is created each time a method is invoked. A frame is destroyed when its
method invocation completes.
PC (program counter) register. It contains the address of the Java virtual machine
instruction currently being executed.
7) Execution Engine
It contains:
1) A virtual processor
The means that allows Java to solve both the security and the portability problems is
that the output of a Java compiler is not executable code but it is the Bytecode.
JVM is an interpreter for bytecode. The fact that a Java program is executed by JVM
helps solve the major problems associated with downloading programs over the Internet.
Translating a Java program into bytecode helps makes it much easier to run a program
in a wide variety of environments. This is because only the JVM needs to be
implemented for each platform.
Once the run-time package exists for a given system, any Java program can run on it. If
a Java program is compiled to its subject code, then different versions of the same
program would exist for each type of CPU connected to the Internet. This is not a
practical solution. Thus, the understanding of bytecode is the most effective way to
create strictly portable programs. Now, if a Java program is interpreted, it also helps to
make it secure. Since the execution of every Java program is under the control of the
JVM, the JVM can contain the program, and prevent it from generating side effects
outside of the system. The use of byte Code enables the Java run-time system to execute
programs much faster.
Sun provides a facility called Just In Time (JIT) compiler for bytecode. It is not possible
to compile an entire Java program into executable code all at once, because Java
performs various run-time checks that can be done only at run time. JIT compiles the
code 3.S and when needed.