Lecture 2
Lecture 2
Java
Objectives
At the end of the lesson, the student should be able to:
• Discuss the history of Java
• Describe the features of Java technology such as the Java virtual
machine, garbage collection and code security
• Describe the different phases of a Java program
Java History
• Created in 1991 by James Gosling et al. of Sun Microsystems
• Responding to a need for platform independent language that could
be embedded in various consumer electronic products
• Language was created with 5 main goals:
1. It should be object oriented
2. A single representation of a program could be executed on multiple
operating systems
3. It should fully support network programming
4. It should execute code from remote sources securely
5. It should be easy to use
What is Java Technology?
• A programming language: Java can create all kinds of applications that you could
create using any conventional programming language
• A development environment: Provides a large suite of tools:
• a compiler;
• an interpreter
• a documentation generator
• a class file packaging tool, etc.
• An application environment: Java applications run on any machine where the
Java runtime environment (JRE) is installed
• A deployment environment: There are two main deployment environments:
• The JRE supplied by the Java 2 Software Development Kit (SDK):
• contains the complete set of class files for all the Java technology packages: basic language classes, GUI
component classes, etc.
• The web browser: Most commercial browsers supply a Java technology interpreter and
runtime environment
Some Features of Java
• The Java Virtual Machine (JVM)
• Garbage Collection
• Code Security
JVM (Java Virtual Machine)
• An abstract machine
• A specification that provides runtime environment in which java
bytecode can be executed.
• Available for many hardware and software platforms (i.e. JVM is
platform dependent).
• Enables the Java software to be platform-independent
• Code compilation is done for a generic machine - the JVM
Phases of a Java Program
Phases of a Java Program: Example Java
program
Phases of a Java Program
Phases of a Java Program
Loading and executing a Java program
What the JVM does
The JVM performs following operation:
• Loads code
• Verifies code
• Executes code
Class(Method) Area:
• Class(Method) Area stores per-class
structures such as the runtime constant
pool, field and method data, the code
for methods.
Heap:
• It is the runtime data area in which
objects are allocated.
Internal Architecture of JVM
Stack:
• stores frames - 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.
Internal Architecture of JVM
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.
Internal Architecture of JVM
Program Counter Register:
• contains the address of the
Java virtual machine
instruction currently being
executed.