TM : A Quick Look Java TM : A Quick Look Java somchaip@chula.ac.th - - PowerPoint PPT Presentation

tm a quick look
SMART_READER_LITE
LIVE PREVIEW

TM : A Quick Look Java TM : A Quick Look Java somchaip@chula.ac.th - - PowerPoint PPT Presentation

TM : A Quick Look Java TM : A Quick Look Java somchaip@chula.ac.th somchaip@chula.ac.th Programming Languages Programming Languages 1957 1957 : : Fortran Fortran 1959 1959 : : Cobol, Lisp Cobol, Lisp 1964 1964 :


slide-1
SLIDE 1

Java JavaTM

TM : A Quick Look

: A Quick Look

somchaip@chula.ac.th somchaip@chula.ac.th

slide-2
SLIDE 2

Programming Languages Programming Languages

  • 1957

1957 : : Fortran Fortran

  • 1959

1959 : : Cobol, Lisp Cobol, Lisp

  • 1964

1964 : : Basic Basic

  • 1971

1971 : : Pascal Pascal

  • 1972

1972 : : C, Prolog C, Prolog

  • 1983

1983 : : C C+ + + +

  • 1995

1995 : : Java Java

  • 2001

2001 : : C# , J# C# , J#

slide-3
SLIDE 3

Sun Sun’ ’s Green Project s Green Project

  • 1990

1990 : : Sun Sun’ ’s Green project s Green project

– – “ “The convergence of digitally controlled The convergence of digitally controlled consumer devices and computers consumer devices and computers. .” ”

  • 1992

1992 : : StarSeven StarSeven (* (* 7 7) ) handheld handheld wireless PDA using Oak as wireless PDA using Oak as prog

  • prog. lang.

. lang.

– – * 7 went ch11 * 7 went ch11

  • 1995 : Oak was renamed to Java at

1995 : Oak was renamed to Java at the time when Internet & WWW was the time when Internet & WWW was booming. booming.

slide-4
SLIDE 4

Java Technology Java Technology

  • Java Programming Language

Java Programming Language

  • Java Platform

Java Platform

– – Java Virtual Machine Java Virtual Machine – – Java API Java API

slide-5
SLIDE 5

Java VM Java VM

  • Solaris

Solaris

  • Linux

Linux

  • Windows

Windows

  • Mac OS X

Mac OS X

  • HP

HP-

  • UX

UX

  • IBM

IBM-

  • AIX, OS/390

AIX, OS/390

  • PDA

PDA

  • Java

Java-

  • enabled cell

enabled cell phones phones

  • GameBoy

GameBoy Advance Advance

  • ...

...

slide-6
SLIDE 6

Java API Java API

version version # # packages packages # # classes classes 1.0 1.0 8 8 212 212 1.1 1.1 23 23 504 504 1.2 1.2 59 59 1520 1520 1.3 1.3 76 76 ~ 1800 ~ 1800 1.4 1.4 135 135 ~ 2800 ~ 2800 1.5 1.5 ??? ??? ???? ????

Java 2

slide-7
SLIDE 7

Java Platforms Java Platforms

  • Standard Edition

Standard Edition ( (J2SE J2SE) )

– – client client-

  • side general

side general-

  • purpose applications

purpose applications

  • Enterprise Edition

Enterprise Edition ( (J2EE J2EE) )

– – multi multi-

  • tier server

tier server-

  • centric applications

centric applications

  • Micro Edition

Micro Edition ( (J2ME J2ME) )

– – consumer and embedded devices consumer and embedded devices

slide-8
SLIDE 8

Java Technology Java Technology

  • James Gosling :

James Gosling :

– – “… “… software VLSI, end software VLSI, end-

  • to

to-

  • end, side

end, side-

  • to

to-

  • side, homogenous view of heterogeneity

side, homogenous view of heterogeneity reality ... reality ...” ”

slide-9
SLIDE 9

Java Logos Java Logos

2003 1995

  • 2002
slide-10
SLIDE 10

Sun's Stat. Sun's Stat.

  • 500 million desktop PCs run Java applets

500 million desktop PCs run Java applets

  • 3 million

3 million+ + professional Java developers professional Java developers

  • Of all Java developers

Of all Java developers ( (Evans Data, 2002 Evans Data, 2002): ):

– – 58% develop desktop applications 58% develop desktop applications – – 50% develop intranet applets 50% develop intranet applets – – 38% develop internet applets 38% develop internet applets

  • > 36 million Java runtime

> 36 million Java runtime env

  • env. downloads

. downloads

  • JRE downloads surging, now about 3 million

JRE downloads surging, now about 3 million per month per month

slide-11
SLIDE 11

Why Java ? Why Java ?

slide-12
SLIDE 12

Popularity Popularity

3.7

JavaScript

10 3.8

Delphi/Pascal/Kylix

9 4.1

C#

8 6.1

SQL

7 9.5

PHP

6 15.2 (Visual) Basic 5 18.3

Perl

4 33.8

C+ +

3 36.7

C

2 47.4

Java

1

Ratings Program m ing Language Position

slide-13
SLIDE 13

The Biggest Open Problem The Biggest Open Problem I n Programming Languages I n Programming Languages

  • Increasing Programmer Productivity

Increasing Programmer Productivity

– – Write programs correctly Write programs correctly – – Write programs quickly Write programs quickly – – Write programs easily Write programs easily

http://research.microsoft.com/~toddpro/papers/disruptive.ppt

slide-14
SLIDE 14

Java Programming Lang. Java Programming Lang.

  • James Gosling :

James Gosling :

– – Life is too short, Java lets him do more Life is too short, Java lets him do more coding, less debugging coding, less debugging – – Java beats C and C+ + by a factor of 2 in Java beats C and C+ + by a factor of 2 in developer productivity. developer productivity.

slide-15
SLIDE 15

Java : Design Goals Java : Design Goals

Java technology must enable the development of secure, high performance, and highly robust applications on multiple platforms in heterogeneous, distributed networks.

slide-16
SLIDE 16

Java Programming Lang. Java Programming Lang.

  • Simple, Familiar, Object

Simple, Familiar, Object-

  • Oriented

Oriented

  • Robust, Secure

Robust, Secure

  • Architecture Neutral, Portable

Architecture Neutral, Portable

  • High Performance

High Performance

  • Interpreted, Threaded, Dynamic

Interpreted, Threaded, Dynamic

Platform independence is the main reason for using Java (ComputerWorld’s survey)

slide-17
SLIDE 17

Simple, Familiar, and OO Simple, Familiar, and OO

  • easily program

easily program

  • Bill Joys : Java = C+ +

Bill Joys : Java = C+ + -

  • -
  • provide a clean & efficient object

provide a clean & efficient object-

  • based

based development platform development platform

slide-18
SLIDE 18

Robust and Secure Robust and Secure

  • Robust

Robust

– – strict compile time checking strict compile time checking – – strict run strict run-

  • time checking

time checking – – automatic garbage collection automatic garbage collection – – support exception handling & assertion support exception handling & assertion

  • Secure

Secure

– – no pointer no pointer – – verify verify bytecode bytecode before class loading before class loading – – sandbox sandbox

slide-19
SLIDE 19

Arch Neutral & Portable Arch Neutral & Portable

  • Write Once Run Anywhere (WORA)

Write Once Run Anywhere (WORA)

– – compiled to Java compiled to Java bytecode bytecode – – run on Java VM run on Java VM – – fixed sizes, formats, and behaviors of all fixed sizes, formats, and behaviors of all primitive data types primitive data types – – behave (almost) the same on multi behave (almost) the same on multi-

  • platforms

platforms

  • solve distribution & version problems

solve distribution & version problems

  • can be deployed into heterogeneous

can be deployed into heterogeneous network environments network environments

slide-20
SLIDE 20

High Performance High Performance

  • Hotspot VM is highly tunable

Hotspot VM is highly tunable

  • the garbage collector runs as a low

the garbage collector runs as a low-

  • priority thread

priority thread

  • support native codes for compute

support native codes for compute-

  • intensive operations

intensive operations

  • JVM performance keeps improving

JVM performance keeps improving

slide-21
SLIDE 21

I nterpreted, Thread, Dynamic I nterpreted, Thread, Dynamic

  • linking is lightweight and incremental

linking is lightweight and incremental

  • faster development cycle

faster development cycle

  • support multithreading at the

support multithreading at the language level w/ sync. primitives language level w/ sync. primitives

  • language and run

language and run-

  • time system are

time system are dynamically linked on demand dynamically linked on demand

slide-22
SLIDE 22

Java Java’ ’s WORA s WORA

  • promote readability

promote readability

  • Java code will survive.

Java code will survive.

  • Write today, use next year.

Write today, use next year.

  • Easy to maintain at a fixed level of functionality

Easy to maintain at a fixed level of functionality

  • Java enables evolution

Java enables evolution

– – bad code dies bad code dies – – good code lives on (modified, evolves, good code lives on (modified, evolves, becomes better) becomes better)

http://www.wgrosso.com/Articles/Presentations/PresentationonJavaasaProg.html

slide-23
SLIDE 23

WORA = = Community WORA = = Community

  • Reuse lots of code from different places

Reuse lots of code from different places

– – Very little need to worry about platform Very little need to worry about platform dependencies dependencies – – Widespread adoption of coding conventions Widespread adoption of coding conventions – – And large And large-

  • scale libraries

scale libraries

  • New programming style

New programming style

– – Write Half, Steal the Rest Write Half, Steal the Rest

http://www.wgrosso.com/Articles/Presentations/PresentationonJavaasaProg.html

slide-24
SLIDE 24

Language Features Language Features

  • 1995 (1.0) : first public release

1995 (1.0) : first public release

  • 1997 (1.1) : nested classes

1997 (1.1) : nested classes

  • 2001 (1.4) : assert

2001 (1.4) : assert

  • 2003 (1.5) :

2003 (1.5) :

– – generics, generics, enum enum, enhanced for, , enhanced for, autoboxing/unboxing autoboxing/unboxing, , varargs varargs, static , static import, metadata. import, metadata. increase expressiveness, increase safety

slide-25
SLIDE 25

Features Removed from C+ + Features Removed from C+ +

  • No

No typedef typedef, define, preprocessor , define, preprocessor

  • No multiple inheritance

No multiple inheritance

  • No operator overloading

No operator overloading

  • No automatic coercion

No automatic coercion

  • No pointers

No pointers

slide-26
SLIDE 26

Demo

slide-27
SLIDE 27

Object Technology in Java Object Technology in Java

  • Encapsulation

Encapsulation

  • Polymorphism

Polymorphism

  • Single Inheritance

Single Inheritance

  • Dynamic binding

Dynamic binding

slide-28
SLIDE 28
slide-29
SLIDE 29

javadoc javadoc

  • g

generates enerates HTML HTML pages pages of

  • f API

API documentation documentation from from Java Java source source files files

  • automatically

automatically adds adds cross cross-

  • reference

reference links links

  • produces

produces one

  • ne complete

complete document document each each time time it it is is run run

  • relies

relies on

  • n the

the java java compiler compiler to to do do its its job job

slide-30
SLIDE 30

Commenting the Source Commenting the Source

  • javadoc

javadoc comment /* * * / comment /* * * /

  • comments are written in HTML

comments are written in HTML

  • special tags embedded in comments

special tags embedded in comments

– – @author @author @deprecated @deprecated – – @ @param param @throws @throws – – @return @return @since @since – – @see @see ... ...

slide-31
SLIDE 31

/* * * Returns the trigonometric cosine of an angle. Special cases: * < ul> < li> If the argument is NaN or an infinity, then the * result is NaN.< /ul> * < p> A result must be within 1 ulp of the correctly rounded * result. Results must be semi-monotonic. * * @param a an angle, in radians. * @return the cosine of the argument. * / public static double cos(double a) { return StrictMath.cos(a); } /* * * Returns the trigonometric cosine of an angle. Special cases: * < ul> < li> If the argument is NaN or an infinity, then the * result is NaN.< /ul> * < p> A result must be within 1 ulp of the correctly rounded * result. Results must be semi-monotonic. * * @param a an angle, in radians. * @return the cosine of the argument. * / public static double cos(double a) { return StrictMath.cos(a); }

javadoc javadoc : Comments : Comments

slide-32
SLIDE 32

javadoc javadoc : HTML : HTML

slide-33
SLIDE 33

javadoc javadoc

  • can

can run run on

  • n .

.java

java source source files files that that are are pure pure stub stub files files with with no no method method bodies bodies

  • can

can generate generate documentation documentation for for source source files files whose whose code code is is incomplete incomplete

  • can

can customize customize the the content content and and format format

  • f
  • f the

the Javadoc Javadoc tool tool'

's

s output

  • utput by

by using using doclets doclets (HTML, XML, MIF, RTF) (HTML, XML, MIF, RTF)

  • use 3

use 3rd

rd party

party s/w s/w to produce other to produce other formats e.g., Windows HTMLHLP formats e.g., Windows HTMLHLP

slide-34
SLIDE 34

Java Web Start Java Web Start

slide-35
SLIDE 35

Java Plug Java Plug-

  • in

in

  • enables Java 2 applets to be run under

enables Java 2 applets to be run under Sun Sun’ ’s JRE in Netscape Navigator and s JRE in Netscape Navigator and Internet Explorer. Internet Explorer.

  • supports cookies

supports cookies

  • allow applet persistence across sessions

allow applet persistence across sessions

  • applet caching

applet caching

  • Java

Java-

  • to

to-

  • JavaScript communication

JavaScript communication

  • Common DOM API

Common DOM API

slide-36
SLIDE 36

User I nterface API User I nterface API

  • AWT

AWT

  • Swing

Swing

  • Accessibility API

Accessibility API

  • Java 2D API

Java 2D API

  • Input Methods

Input Methods

  • Sound

Sound

slide-37
SLIDE 37

Abstract Window Toolkit Abstract Window Toolkit

  • rich set of UI components

rich set of UI components

  • robust event

robust event-

  • handling model

handling model

  • graphics and imaging classes

graphics and imaging classes

  • layout managers

layout managers

  • data transfer class (cut

data transfer class (cut-

  • &

&-

  • paste

paste through native clipboard) through native clipboard)

slide-38
SLIDE 38

Swing Swing

  • Graphical User Interface (GUI)

Graphical User Interface (GUI) component toolkit. component toolkit.

  • Complete set of user

Complete set of user-

  • interface

interface elements written entirely in Java. elements written entirely in Java.

  • Integrated into the Java 2 platform

Integrated into the Java 2 platform (1.2 or higher). (1.2 or higher).

slide-39
SLIDE 39

Swing vs. AWT Swing vs. AWT

  • Swing

Swing

– – Lightweight Lightweight – – Complex Complex – – Pluggable L&F Pluggable L&F – – Pure Java Pure Java – – Java 1.2, ... Java 1.2, ...

  • AWT

AWT

– – Heavyweight Heavyweight – – Primitive Primitive – – Single L&F Single L&F – – Not Pure Java Not Pure Java – – Java 1.0, ... Java 1.0, ...

slide-40
SLIDE 40

Swing vs. AWT Swing vs. AWT

  • JApplet

JApplet

  • JFrame

JFrame

  • JButton

JButton, , JCheckbox JCheckbox, , JRadioButton JRadioButton, , JComboBox JComboBox, , JDialog JDialog, , JLabel JLabel, , JList JList, , JSlider JSlider, , JTextComponent JTextComponent, , ... ...

  • Applet

Applet

  • Frame

Frame

  • Button, Checkbox,

Button, Checkbox, Choice, Dialog, Choice, Dialog, Label, List, Label, List, Scrollbar, Scrollbar, TextComponent TextComponent, ... , ...

slide-41
SLIDE 41

Distributed Object App. Distributed Object App.

  • Server

Server

– – create some remote objects create some remote objects – – make references to the objects accessible make references to the objects accessible – – wait for client to invoke methods on wait for client to invoke methods on these objects these objects

  • Client

Client

– – get remote references get remote references – – invoke methods on these references invoke methods on these references

slide-42
SLIDE 42

Remote Method I nvocation Remote Method I nvocation

  • RMI

RMI allows allows an an object

  • bject running

running in in one

  • ne

JVM JVM to to invoke invoke methods methods on

  • n an

an object

  • bject

running running in in another another JVM JVM

slide-43
SLIDE 43

Distributed App. Distributed App.

  • Cross

Cross-

  • language, cross

language, cross-

  • vendor interoperability

vendor interoperability is achieved via the IIOP (a transport protocol is achieved via the IIOP (a transport protocol for distributed app. written in either IDL or for distributed app. written in either IDL or Java RMI) Java RMI)

  • Java 1.1 : RMI

Java 1.1 : RMI

– – a natural outgrowth of RPC a natural outgrowth of RPC

  • Java 1.2 : Java IDL

Java 1.2 : Java IDL

– – API for interoperability and integration with CORBA API for interoperability and integration with CORBA

  • Java 1.3 : RMI over IIOP

Java 1.3 : RMI over IIOP

– – enabled enabled remote remote objects

  • bjects written

written in in Java Java to to be be accessible accessible from from any any language language via via IIOP IIOP

slide-44
SLIDE 44

Core API Core API

  • lang.

lang.

  • util.

util.

– – logging logging – – perference perference – – collection collection – – regexp regexp – – jar, zip jar, zip

  • I/O & new I/O

I/O & new I/O

  • networking

networking

  • security

security

  • locale

locale

  • JavaBean

JavaBean

  • XML

XML

  • native interface

native interface

slide-45
SLIDE 45

Collection Framework Collection Framework

  • Java 1 : Vector,

Java 1 : Vector, Hashtable Hashtable

  • Java 2 :

Java 2 :

< < Collection> > < < Set> > < < List> > < < SortedSet> > < < Map> > < < SortedMap> >

slide-46
SLIDE 46

I mplementations I mplementations

  • General

General-

  • purpose

purpose

– – ArrayList ArrayList, , LinkedList LinkedList – – TreeSet TreeSet, , HashSet HashSet, , LinkedHashSet LinkedHashSet, , – – TreeMap TreeMap, , HashMap HashMap, , LinkedHashMap LinkedHashMap

  • Wrapper

Wrapper

– – synchronized synchronized – – unmodifiable unmodifiable

  • Convenience

Convenience

– – Array.asList Array.asList – – ... ...

  • Legacy

Legacy

– – Vector, Vector, Hashtable Hashtable

  • Special purpose

Special purpose

– – WeakHashMap WeakHashMap, , IdentityHashMap IdentityHashMap

  • Algorithms

Algorithms

– – sort, search, fill, ... sort, search, fill, ...

slide-47
SLIDE 47

JNI : Native I nterface JNI : Native I nterface

  • native method can

native method can

– – create, access, and update its own objects create, access, and update its own objects including objects passed to it including objects passed to it – – call Java methods call Java methods – – load and get information about Java classes load and get information about Java classes

slide-48
SLIDE 48

An Example An Example

class HelloWorld { public native void displayHelloWorld(); static { System.loadLibrary("hello"); } public static void main(String[] args) { new HelloWorld().displayHelloWorld(); } }

javac HelloWorld.java javah –jni HelloWorld HelloWorld.java

slide-49
SLIDE 49

An Example An Example

#include <jni.h> #include "HelloWorld.h" #include <stdio.h> JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) { printf("Hello world!\n"); return; }

cl -Ic:\java\include -Ic:\java\include\win32

  • LD HelloWorld.c -Fehello.dll

HelloWorld.c

slide-50
SLIDE 50

Reflection API Reflection API

  • examine classes

examine classes

  • manipulate an instance of a classes

manipulate an instance of a classes whose name is not known until runtime whose name is not known until runtime

  • invoke a method whose name is not

invoke a method whose name is not known until runtime known until runtime

  • usually used for writing development

usually used for writing development tools e.g., debuggers, class browsers, ... tools e.g., debuggers, class browsers, ...

slide-51
SLIDE 51

An Example An Example : Java : Java

public void init() { Button btOK = new Button("OK"); btOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(“I’m OK”); } } ); add(btOK); Button btCancel = new Button("CANCEL"); btCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(“I was cancelled”); } } ); add(btCancel); }

slide-52
SLIDE 52

An Example : VB An Example : VB

Private Sub OK_Click() Debug.print "I'm OK" End Sub Private Sub CANCEL_Click() Debug.print "I was cancelled" End Sub public void onButtonPushed_OK() { System.out.println("I'm OK"); } public void onButtonPushed_CANCEL() { System.out.println("I'm Cancelled"); }

slide-53
SLIDE 53

public void init() { ActionListener btListener = new ActionListener() { public void actionPerformed(ActionEvent e) { methodInvoke("onButtonPushed_" + e.getActionCommand()); } }; Button btOK = new Button("OK"); btOK.addActionListener(btListener); add(btOK); Button btCancel = new Button("CANCEL"); btCancel.addActionListener(btListener); add(btCancel); } public void methodInvoke(String metName) { try { Class c = this.getClass(); Method met = c.getMethod(metName, new Class[0]); met.invoke(this, new Object[0]); } catch (Exception ex) { ex.printStackTrace(); } }