You are on page 1of 23

Lecture One

Introduction to Java

Ashish Bajpai ,Assistant professor


1
Department of CSE, KIET 1
Book’s Name
1. The complete reference of java 2 (J2SE 6 Edition)
Author : Herbert Schieldt

2. Programming in Java2
Author : E. Balagurusamy

Web Source:
 http://java.sun.com/docs/books/tutorial/
 http://java.sun.com/javase/6/docs

Ashish Bajpai ,Assistant professor


2
Department of CSE, KIET 2
History of Java
 Java is a general purpose object oriented programming
language.
 Developed by Sun Microsystems. (James Gostling)
 Initially called “Oak” but was renamed as “Java” in 1995.
 Initial motivation is to develop a platform independent
language to create software to be embedded in various
consumer electronics devices.
 Become the language of internet. (portability and security).

Ashish Bajpai ,Assistant professor


3
Department of CSE, KIET 3
Features of Java
1. Simple, Small and Familiar
2. Compiled and Interpreted
3. Object Oriented
4. Platform Independent and portable
5. Robust and Secure
6. Distributed / Network Oriented
7. Multithreaded and Interactive
8. High Performance
9. Dynamic

Ashish Bajpai ,Assistant professor


4
Department of CSE, KIET 4
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Simple, Small and Familiar
Similar to C/C++ in syntax
But eliminates several complexities of
No operator overloading
No direct pointer manipulation or pointer
arithmetic
No multiple inheritance
No malloc() and free() – handles memory
automatically

Ashish Bajpai ,Assistant professor


5
Department of CSE, KIET 5
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Compiled and Interpreted
Java works in two stage
Java compiler translate the source code into byte code.
Java interpreter converts the byte code into machine
level representation.
Byte Code:
-A highly optimized set of instructions to be executed by
tehe java runtime system, known as java virtual
machine (JVM).
-Not executable code.
Java Virtual Machine (JVM):
- Need to be implemented for each platform.
- Although the details vary from machine to machine, all
JVM understand the same byte code.
Ashish Bajpai ,Assistant professor
6
Department of CSE, KIET 6
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Java Virtual Machine
 Java compiler produces an intermediate code known as
byte code for a machine, known as JVM.
 It exists only inside the computer memory.

Java Program Java Compiler Virtual Machine

 Machine code is generated by the java interpreter by acting


as an intermediary between the virtual machine and real
machine.

Bytecode Java Interpreter Machine Code


Ashish Bajpai ,Assistant professor
7
Department of CSE, KIET 7
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Object Oriented
Fundamentally based on OOP
Classes and Objects
Efficient re-use of packages such that the
programmer only cares about the interface and not
the implementation
The object model in java is simple and easy to
extend.

Ashish Bajpai ,Assistant professor


8
Department of CSE, KIET 8
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Platform Independent and Portable
“Write-Once Run-Anywhere”
Changes in system resources will not force any change in the
program.
The Java Virtual Machine (JVM) hides the complexity of
working on a particular platform
Convert byte code into machine level representation.

Ashish Bajpai ,Assistant professor


9
Department of CSE, KIET 9
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Robust and Secure
Designed with the intention of being secure
No pointer arithmetic or memory management!
Strict compile time and run time checking of data
type.
Exception handling
It verify all memory access
Ensure that no viruses are communicated with an
applet.

Ashish Bajpai ,Assistant professor


10
Department of CSE, KIET 10
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Distributed and Network Oriented
• Java grew up in the days of the Internet
– Inherently network friendly
– Original release of Java came with Networking
libraries
– Newer releases contain even more for handling
distributed applications
• RMI, Transactions

Ashish Bajpai ,Assistant professor


11
Department of CSE, KIET 11
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Multithreaded and Interactive
Handles multiple tasks simultaneously.
Java runtime system contains tools to support multiprocess
synchronization and construct smoothly running interactive
systems.

Ashish Bajpai ,Assistant professor


12
Department of CSE, KIET 12
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
High Performance
Java performance is slower than C
Provisions are added to reduce overhead at runtime.
Incorporation of multithreading enhance the overall
execution speed.
Just-in-Time (JIT) can compile the byte code into
machine code.
• Can sometimes be even faster than compiled C code!

Ashish Bajpai ,Assistant professor


13
Department of CSE, KIET 13
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Dynamic
Capable of dynamically linking a new class libraries,
methods and objects.
Java can use efficient functions available in C/C++.
Installing new version of library automatically updates all
programs

Ashish Bajpai ,Assistant professor


14
Department of CSE, KIET 14
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Language of Internet Programming
Java Applets
Security
Portability
1. Applets:
Special java program that can transmitted over the network
and automatically executed by a java-compatible web
browser.
2. Security:
Java compatible web browser can download java applets
without fear of viral infection and malicious agent.
3. Portable:
Java applets can be dynamically downloaded to all the
various types of platforms
Ashish Bajpai ,Assistant connected
professor
Department of CSE, KIET
to the internet 15 15
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Why portable and Secure?
.
The output of java compiler is not executable code.
Once JVM exists for a platform, any java program can run
on it.
The execution of byte code by the JVM makes java
programs portable.
Java program is confined within the java execution
environment and cannot access the other part of the
computer.

Ashish Bajpai ,Assistant professor


16
Department of CSE, KIET 16
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Basics of Java Environments
Java programs normally undergo five phases
Edit
Programmer writes program (and stores program on disk)
Compile
Compiler creates bytecodes from program
Load
Class loader stores bytecodes in memory
Verify
Verifier ensures bytecodes do not violate security
requirements
Execute
Interpreter translates bytecodes into machine language
Ashish Bajpai ,Assistant professor
17
Department of CSE, KIET 17
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Program is created in an
Phase 1 Editor Disk editor and stored on disk
in a file ending with
.java.

Compiler creates
Phase 2 Compiler Disk bytecodes and stores
them on disk in a file
ending with .class.
Primary
Memory
Phase 3 Class Loader Class loader
reads .class files
containing
bytecodes from disk
and puts those
Disk bytecodes in
. .. memory.
..
.

Primary
Memory
Phase 4 Bytecode Verifier Bytecode verifier
confirms that all
bytecodes are
valid and do not
violate Java’s
security
. ..
.. restrictions.
.

Primary
Memory Interpreter reads
Phase 5 Interpreter bytecodes and
translates them into a
language that the
computer can
understand, possibly
storing data values as
the program executes.
. ..
..
Ashish Bajpai ,Assistant professor . 18
Department of CSE, KIET 18
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Java Environment
Development tools-part of java development kit (JDK).
Classes and methods-part of Java Standard Library (JSL),
also known as Application Programming Interface (API).
1. JDK:
Appletviewer ( for viewing applets)
Javac (Compiler)
Java (Interpreter)
Javap (Java disassembler)
Javah (for C header files)
Javadoc ( for creating HTML description)
Jdb (Java Debugger)

Ashish Bajpai ,Assistant professor


19
Department of CSE, KIET 19
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Java Environment
2. Application Package Interface (API)
Contains hundreds of classes and methods grouped into several
functional packages:
Language Support Package
Utility Packages
Input/Output Packages
Networking Packages
AWT Package
Applet Package

Ashish Bajpai ,Assistant professor


20
Department of CSE, KIET 20
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
The Evolution of Java
1. Java 1.0
2. Java 1.1 (Add new library, redefine applet handling and
reconfigured many features.)
3. Java 2 (Second generation). Version no:1.2 (Internal version
number of java library). Also known as J2SE [ Java 2 Platform
Standard Edition].
- Add swing, the collection framework, enhanced JVM etc.
4. J2SE 1.3
5. J2SE 1.4
6. J2SE 1.5
7. J2SE 1.6

Ashish Bajpai ,Assistant professor


21
Department of CSE, KIET 21
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Versions of Java
Three versions of the Java 2 Platform, targetted at different uses
Java 2 Micro Edition (J2ME)
Very small Java environment for smart cards, pages, phones, and set-top
boxes
Subset of the standard Java libraries aimed at limited size and processing
power
Java 2 Standard Edition (J2SE)
The basic platform
J2SE can be used to develop client-side standalone applications or applets.
Java 2 Enterprise Edition (J2EE)
For business applications, web services, mission-critical systems
Transaction processing, databases, distribution, replication

Ashish Bajpai ,Assistant professor


22
Department of CSE, KIET 22
05/07/2008 Mosarratj Jahan, Dept. of CSE, DU
Chapter One of the text book.
Software Used for the Course:
1.Java 2 (Version 6)
2.NetBean IDE
3.J creature
- Sun.java.com

Ashish Bajpai ,Assistant professor


23
Department of CSE, KIET 23
Mosarratj Jahan, Dept. of CSE, DU

You might also like