0% found this document useful (0 votes)
54 views58 pages

Internet and Java Application: 1. Background

This document provides an overview of Java and its features. It discusses Java's advantages including productivity through object orientation and standard libraries, simplicity and safety compared to C/C++, built-in GUI and multimedia support, extensive network capabilities, multithreading, and portability across platforms. It also outlines Java's core features such as being machine independent, secure, simple, object-oriented, robust, architecture-neutral, portable, network-savvy, interpreted for high performance, multithreaded, distributed, and dynamic.

Uploaded by

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

Internet and Java Application: 1. Background

This document provides an overview of Java and its features. It discusses Java's advantages including productivity through object orientation and standard libraries, simplicity and safety compared to C/C++, built-in GUI and multimedia support, extensive network capabilities, multithreading, and portability across platforms. It also outlines Java's core features such as being machine independent, secure, simple, object-oriented, robust, architecture-neutral, portable, network-savvy, interpreted for high performance, multithreaded, distributed, and dynamic.

Uploaded by

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

Internet And Java Application

MCA-501(N2)

Course Overview
Introduction

1. Background
Objectives
give a nontechnical overview of Java

Contents
1. Java, etc.
2. Java's Advantages
3. Java's Disadvantages
4. Some History
5. Types of Java Code
6. Java Safety
7. Core Libraries
8. Notes on J2SE Installation

Features of Java
Machine Independent
Secure
Simple
Object-Oriented
Robust
Architecture-Neutral
Portable
Network-Savvy
Interpreted and High Performance
Multithreaded
Distributed
Dynamic

Language features

simple

syntax is based on C++ (familiarity easier transition for programmers)


removed many rarely-used, confusing features

e.g., operator overloading, multiple inheritance, automatic coercions


added memory management (reference count/garbage collection hybrid)

object-oriented

OOP facilities similar C++, all member functions dynamically bound


pure OOP everything is a class, no independent functions*

network-savvy

extensive libraries for coping with TCP/IP protocols like HTTP & FTP
Java applications can access remote URL's the same as local files

Language features (cont.)


robust
for embedded systems, reliability is essential
Java combines extensive static checking with dynamic checking
closes C-style syntax loopholes
compile-time checking more effective
even so, the linker understands the type system & repeats many checks
Java disallows pointers as memory accessors
arrays & strings are ADTs, no direct memory access
eliminates many headaches, potential problems

secure

in a networked/distributed environment, security is essential


execution model enables virus-free*, tamper-free* systems
downloaded applets cannot open, read, or write local files
uses authentication techniques based on public-key encryption

note: the lack of pointers closes many security loopholes by itself

Language features (cont.)


architecture-neutral

want to be able to run Java code on multiple platforms


neutrality is achieved by mixing compilation & interpretation
Java programs are translated into byte code by a Java compiler
byte code is a generic machine code
byte code is then executed by an interpreter (Java Virtual Machine)
must have a byte code interpreter for each hardware platform
byte code will run on any version of the Java Virtual Machine

Alternative execution model:


can define and compile applets (little applications)
not stand-alone, downloaded & executed by a Web browser

portable

architecture neutral + no implementation dependent features


size of primitive data types are set
libraries define portable interfaces

Language features (cont.)


interpreted

interpreted faster code-test-debug cycle


just-in-time compilation (classes are loaded and recompiled on demand)
on-demand linking (if class/library in not needed, won't be linked)
does interpreted mean slow?

high-performance

faster than traditional interpretation since byte code is "close" to native code
than still somewhat slower than a compiled language (e.g., C++)

multi-threaded

a thread is like a separate program, executing concurrently


can write Java programs that deal with many tasks at once by defining multiple
threads (same shared memory, but semi-independent execution)
threads are important for multi-media, Web applications

Language features (cont.)


dynamic

Java was designed to adapt to an evolving environment


e.g., the fragile class problem
in C++, if you modify a parent class, you must recompile all derived classes
in Java, memory layout decisions are NOT made by the compiler
instead of compiling references down to actual addresses, the Java compiler
passes symbolic reference info to the byte code verifier and the interpreter
the Java interpreter performs name resolution when classes are being linked, then
rewrites as an address
thus, the data/methods of the parent class are not determined until the linker loads
the parent class code
if the parent class has been recompiled, the linker automatically gets the updated
version
Note: the extra name resolution step is price for handling the fragile class problem

JDK Editions
Java Standard Edition (J2SE)
J2SE can be used to develop client-side standalone
applications or applets.
Java Enterprise Edition (J2EE)
J2EE can be used to develop server-side appli. such as
Java servlets
Java Server Pages.
Java Micro Edition (J2ME)
J2ME can be used to develop applications for mobile
devices such as cell phones.

1. Java, J2SE, JSDK, JDK, JRE


There are several 'Java' names:
Java is the name of the language
Java 2 is the current version

the language + tools (e.g. compiler) is called


J2SE, the Java 2 Standard Edition
J2SE 1.5.0. is the current version
its also known as J2SE 5.0

the same
thing
continued

There are two version of J2SE which


contain different amounts of tools:
JSDK: the full version
JRE: just enough tools to run already
compiled programs

continued

JSDK
stands for "Java Software Development Kit
JDK is the old name for JDSK
don't be surprised to also see J2SDK
or Java SDK

continued

JSDK contains all the libraries


(packages), compiler, and other tools fo
r writing/running/debugging Java code.
JRE = "Java Runtime System"
a cut-down version of JSDK with only the
packages/tools needed for running Java co
de
most often used by Web browsers

Features of Java
Machine Independent
Secure
Simple
Object-Oriented
Robust
Architecture-Neutral
Portable
Network-Savvy
Interpreted and High Performance
Multithreaded
Distributed
Dynamic

Language features

simple

syntax is based on C++ (familiarity easier transition for programmers)


removed many rarely-used, confusing features

e.g., operator overloading, multiple inheritance, automatic coercions


added memory management (reference count/garbage collection hybrid)

object-oriented

OOP facilities similar C++, all member functions dynamically bound


pure OOP everything is a class, no independent functions*

network-savvy

extensive libraries for coping with TCP/IP protocols like HTTP & FTP
Java applications can access remote URL's the same as local files

Language features (cont.)


robust
for embedded systems, reliability is essential
Java combines extensive static checking with dynamic checking
closes C-style syntax loopholes
compile-time checking more effective
even so, the linker understands the type system & repeats many checks
Java disallows pointers as memory accessors
arrays & strings are ADTs, no direct memory access
eliminates many headaches, potential problems

secure

in a networked/distributed environment, security is essential


execution model enables virus-free*, tamper-free* systems
downloaded applets cannot open, read, or write local files
uses authentication techniques based on public-key encryption

note: the lack of pointers closes many security loopholes by itself

Language features (cont.)


architecture-neutral

want to be able to run Java code on multiple platforms


neutrality is achieved by mixing compilation & interpretation
Java programs are translated into byte code by a Java compiler
byte code is a generic machine code
byte code is then executed by an interpreter (Java Virtual Machine)
must have a byte code interpreter for each hardware platform
byte code will run on any version of the Java Virtual Machine

Alternative execution model:


can define and compile applets (little applications)
not stand-alone, downloaded & executed by a Web browser

portable

architecture neutral + no implementation dependent features


size of primitive data types are set
libraries define portable interfaces

Language features (cont.)


interpreted

interpreted faster code-test-debug cycle


just-in-time compilation (classes are loaded and recompiled on demand)
on-demand linking (if class/library in not needed, won't be linked)
does interpreted mean slow?

high-performance

faster than traditional interpretation since byte code is "close" to native code
than still somewhat slower than a compiled language (e.g., C++)

multi-threaded

a thread is like a separate program, executing concurrently


can write Java programs that deal with many tasks at once by defining multiple
threads (same shared memory, but semi-independent execution)
threads are important for multi-media, Web applications

Language features (cont.)


dynamic

Java was designed to adapt to an evolving environment


e.g., the fragile class problem
in C++, if you modify a parent class, you must recompile all derived classes
in Java, memory layout decisions are NOT made by the compiler
instead of compiling references down to actual addresses, the Java compiler
passes symbolic reference info to the byte code verifier and the interpreter
the Java interpreter performs name resolution when classes are being linked, then
rewrites as an address
thus, the data/methods of the parent class are not determined until the linker loads
the parent class code
if the parent class has been recompiled, the linker automatically gets the updated
version
Note: the extra name resolution step is price for handling the fragile class problem

2. Javas Advantages
Productivity
object orientation
many standard libraries (packages)

Simpler/safer than C, C++


no pointer arithmetic, has automatic garbage
collection, has array bounds checking, etc.

continued

GUI features
mostly located in the Swing and Abstract
Windowing Toolkit (AWT) packages

Multimedia
2D and 3D graphics, imaging, animations,
audio, video, etc.

continued

Network support
communication with other machines/apps
variety and standards:
sockets, RMI, CORBA

security, resource protection

Multithreading / concurrency
can run several threads at once

continued

Portablility / Platform Independence


write once; run anywhere
only one set of libraries to learn

Supports native code


can integrate legacy code

J2SE is free
continued

Good programming environments:


Eclipse, Blue J, JBuilder, NetBeans, Sun
One Studio
do not use them when first learning Java
http://java.coe.psu.ac.th/Tool.html

Applets (and Java Web Start)


eliminates the need for explicit software
installation.

continued

Good for teaching computing


many important ideas in one place

Its new!
~30 years since C++ introduced

3. Javas Disadvantages
Java/J2SE is still being developed
many changes between versions

Sun has not guaranteed backward


compatibility of future versions of Java.
at the moment, when old-style code is
compiled, the compiler gives a deprecation
warning, but will still accept it
continued

Java compilation/execution was slow,


but ...
not any more: J2SE 1.5 is the same speed
as C++ (perhaps a tiny bit slower for some
things)
there are compilers to native code, but they
destroy the write one; run anywhere idea
the first version of Java, back in 1995, was
about 40 times slower than C++
continued

Cross-platform testing and debugging


has been a problem (due to
inconsistencies)
Write once; run anywhere means that
some local OS features weren't
supported:
e.g. right button actions under Windows
no joysticks, special keypads
this is fixed in the latest versions of Java
continued

Javas security restrictions makes some


code hard to write:
cannot see much of a local machine
newer J2SE versions make this easier

The existing code base (in C, VB, etc.)


means that people do not want to
rewrite applications in Java.

continued

Embedded Systems
Sun Microsystems (Javas inventor) sees this
as a major future market for Java
J2ME (Java 2 Micro Edition) is a cut-down
version of Java
J2ME is the main programming environment
for mobile devices
continued

Slow Internet connections


makes it difficult (and irritating) to download
medium/large size applets
e.g. GIF89a/flash files have replaced Java
animations

Lots to learn
Java language (small) and Java libraries
(very, very large)

continued

There seem to be few serious Java


applications. But ...
the Java compiler (javac) is written in Java
most custom Java applications are internal
to a company
they dont have the high profile of major vendor
software

4. Some History
In 1991, Sun Microsystems set up a
research project to develop a language for pr
ogramming intelligent consumer electronics
e.g. video recorders, TVs, toasters

The language was called Oak (later changed


to Java). Developed by James Gosling, and
others.

August 1993: the project was cancelled


after two commercial deals fell through.
The Web became popular during 1993.
July 1994: Sun restarted work on Java
as a Web programming language
Java contains networking features,
platform portability, and a small runtime sys
tem
continued

Java released May 1995


Netscape supported Java in Navigator
2.0, which gave it an enormous boost

May 1996: JDK 1.0 released.


February 1997: JDK 1.1 released
major changes in the event model used
by the GUI; inner classes introduced

continued

December 1998: JDK 1.2 released


also known as Java 2
much improved GUIs (Swing), graphics

September 2000: J2SDK 1.3 released


still known as Java 2
improved networking, sound, security

continued

February 2002: J2SE 1.4 released


still known as Java 2
improved I/O, GUI improvements, increase
in standard libraries (62% more classes!)

September 2004: J2SE 1.5 released


also known as J2SE 5.0
the language is still Java 2
new stuff: easy IO, generics, enumerated types, au
toboxing, concurrency tools, faster speed, improve
d monitoring/profiling /debugging
see the "J2SE 5.0 in a Nutshell" article
http://java.sun.com/developer/
technicalArticles/releases/j2se15/

Java and C++


What C++ programmers might try to do but cant:
Use pointers (but like we said before, everything is a pointer),
they are called unsafe code.
Include files (use packages instead)
Use global variables (although the concept of global variables
can easily be simulated)
Operator overloading
templates (although the new Java 5.0 has introduced support
for these)
Multiple inheritance (interfaces are used instead)
Destructors (nobody liked them anyways)
Could program a stack class with Objects, and then cast into
an object of another class.

Java and C++ Contd..


No such thing as environment variables as there are with
C/C++ and Unix because this is not OS independent.
Exception: primitive data types such as int, float are not
subclasses of Object. However, there are wrapper classes
Integer, Double, etc.
No overloading of operators (although function overloading
is okay).
No i/o operators <<, >>.
No general multiple inheritance.
No support for typedef, goto, and also does not have delete
operator.

Which Java Should I Use?


The latest version (September 2004) is:
Java 2, J2SE 1.5 (or 5.0)

Textbooks that talk about JDK 1.0, JDK


1.1. should be thrown into a rubbish bin.
Textbooks that talk about JDK 1.2,
J2SDK 1.3 are fine for new Java
programmers.

5. Types of Java Code


There are two kinds of Java code:
We will see
examples in
the next part.

1. Java applications

ordinary programs; stand-alone


they dont run inside a browser
(but they can use Javas GUI libraries)

continued

2. Java applets
they run in a Web browser
they are attached to Web pages, so can be
downloaded easily from anywhere
applets have access to browser features

6. Java Safety
6.1. Java Bytecodes
6.2. Applet advantage/disadvantage
6.3. The Java Virtual Machine
6.4. JVM Restrictions upon Applets
6.5. Relaxing Security

The JVM and Bytecode


Unlike C++ programs, Java programs are not compiled into
machine language
Instead they are compiled into Java bytecode
The bytecode is then interpreted by the Java Virtual Machine
(JVM)
This is the key to Javas universality.
Any compiled Java bytecode can be
run on any valid JVM installed on
any Operating System (on any device,
not just a computer)
With C++ and other compiled languages,
programs must be recompiled for each
particular architecture that it needs to be
run on

6.1. Java Bytecodes


The Java compiler (javac) generates
bytecodes
a set of instructions similar to machine code
not specific to any machine architecture

A class file (holding bytecodes) can be run


on any machine which has a Java runtime
environment.

The Bytecode Advantage


Java runtime
(Pentium)
javac (Pentium)
Java runtime
(Mac)

javac (Mac)
Java code
(.java file)

Java bytecode
(.class file)
javac (UNIX)

Java runtime
(UNIX)

6.2. The Java Virtual Machine


The Java Virtual Machine (JVM) is the
Java runtime environment.
it acts as a layer between the executing byte
codes in an applet and the actual machine
it hides variations between machines
it protects the machine from attack by the
applet

Applet Execution with the JVM

applet
JVM
Web Browser
Client Computer

download
Web page
and applet

applet
Web Server

Application Execution with the JVM

application
JVM
Client Computer

The difference is the


amount of security impo
sed by the JVM
applets are allowed to do
a lot less than application
s

6.3. JVM Restrictions upon Applets


An applet runs in its own memory space
it cannot access the local systems memory
it cannot interfere with other running apps

An applet cannot read/write to files on the


local system (except to special
directories).
e.g. it cannot read system files
continued

An applet cannot easily run local


applications
e.g. system functions, DLLs

An applet can only communicate with its


home server
this restriction is configurable on the clientside

6.4. Relaxing Security


Applets can be signed with trusted
certificates
a browser can be configured to relax
security depending on an applets signature
an advanced topic

7. Core Libraries
Java runtime
standard I/O, networking, applets, basic
windowing, data structures, internationalizatio
n, maths, etc.

Java Foundation Classes


Swing GUI library, Java 2D graphics

continued

Security
digital signatures, message digests

JDBC
database connectivity

Java RMI
remote method invocation

JavaBeans
a software component library

and much, much more

8. Notes on J2SE Installation


Add the bin path for Java to the PATH
environment variable in c:\Autoexec.bat:
set path=%path%;c:\progra~1\java\jdk1.5.0\bin

This says where the Java tools


(e.g. javac) are located.

short for
"program files"

Install the Java Docs/Tutorial


Unzip the Java documentation and
tutorial files:
j2sdk-1_5_0-doc.zip
tutorial.zip (only covers up to 1.4)

Place them as subdirectories \docs and


\tutorial below the directory jdk1.5.0

continued

You should add a Java menu item to the


Start menu, which contains shortcut link
s to the Java documentation and tutorial.
Test which Java you have. In a DOS
window, type:
>

java -version

You might also like