0% found this document useful (0 votes)
9 views21 pages

Lecture 2

This lecture introduces Java, covering its history, features, and the phases of a Java program. Java was created in 1991 by James Gosling to be a platform-independent language with key goals such as object orientation and network programming support. The document also explains the Java Virtual Machine (JVM), garbage collection, and code security mechanisms within the Java Runtime Environment (JRE).

Uploaded by

wilfrednalima285
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views21 pages

Lecture 2

This lecture introduces Java, covering its history, features, and the phases of a Java program. Java was created in 1991 by James Gosling to be a platform-independent language with key goals such as object orientation and network programming support. The document also explains the Java Virtual Machine (JVM), garbage collection, and code security mechanisms within the Java Runtime Environment (JRE).

Uploaded by

wilfrednalima285
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Lecture 2: Introduction to

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

Provides runtime environment - JVM provides definitions for the:


• Memory area
• Class file format
• Register set
• Garbage-collected heap
• Fatal error reporting etc.
Java Virtual Machine
Internal Architecture of JVM
Classloader:
• Classloader is a subsystem of JVM that is
used to load class files.

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.

Native Method Stack:


• It contains all the native
methods used in the
application
Internal Architecture of JVM
Execution Engine- It contains:
• A virtual processor
• Interpreter: Read bytecode stream then
execute the instructions.
• Just-In-Time(JIT) compiler:
• used to improve the performance
• compiles parts of the byte code that
have similar functionality at the same
time - reduces the amount of time
needed for compilation.
• Compiler refers to a translator from
the instruction set of a Java virtual
machine (JVM) to the instruction set
of a specific CPU
Garbage Collection
Garbage collection thread
• responsible for freeing any memory that can be freed.
• Happens automatically during the lifetime of the Java program
Code Security
• attained through the implementation of its Java Runtime
Environment (JRE).
The JRE:
• runs code compiled for a JVM and performs class loading (through
the class loader)
• Performs code verification (through the bytecode verifier)
• Execute code after verification
Code Security
The Class Loader:
• Responsible for loading all classes needed for the Java program
• Adds security by separating the namespaces for the classes of the local file
system from those that are imported from network sources
• limits any Trojan horse applications since local classes are always loaded first.
• Determines the memory layout of the executable is then determined
• Adds protection against unauthorized access to restricted areas of the code since the memory
layout is determined during runtime.
• Tests the format of the code fragments and checks the code fragments for
illegal code that can violate access rights to objects
• The code is then finally executed

You might also like