Java Outline

33
CSTP FS99 CS423 (cotter) 1 Java Outline Intro and Applications Applets and GUI Client / Server • RMI, JDBC

description

Java Outline. Intro and Applications Applets and GUI Client / Server RMI, JDBC. Background. Objective: Platform independent C++ 1991 - 1994 Oak 1994 - JAVA Virtual Machine / Interpreter. Java “Buzzwords”. SimpleObject-Oriented Network-SavyRobust SecureArchitecture neutral - PowerPoint PPT Presentation

Transcript of Java Outline

Page 1: Java  Outline

CSTP FS99 CS423 (cotter) 1

Java Outline

• Intro and Applications• Applets and GUI• Client / Server • RMI, JDBC

Page 2: Java  Outline

CSTP FS99 CS423 (cotter) 2

Background

• Objective: Platform independent C++• 1991 - 1994 Oak• 1994 - JAVA• Virtual Machine / Interpreter

Page 3: Java  Outline

CSTP FS99 CS423 (cotter) 3

Java “Buzzwords”

Simple Object-Oriented

Network-Savy Robust

Secure Architecture neutral

Portable Interpreted

High Performance Multi-threaded

Dynamic

Page 4: Java  Outline

CSTP FS99 CS423 (cotter) 4

JAVA Implementation

Java program

Java program

VM

Java Cmds

Java program

VM

Java Cmds

Java program

VM

Java Cmds

SPARC PowerPC Intel

Page 5: Java  Outline

CSTP FS99 CS423 (cotter) 5

Extension to Internet

• Timing with Internet growth• Same functionality needed• Just implement a new tag (applet)• Browser loads web page & applet

Page 6: Java  Outline

CSTP FS99 CS423 (cotter) 6

Operations Environments

• Applications program (~DOS window)– supports file access

• Applet (browser)– supports Internet linkages.

Page 7: Java  Outline

CSTP FS99 CS423 (cotter) 7

Object Oriented Concepts

• Intent is to model the environment• Combine attributes with functions

Page 8: Java  Outline

CSTP FS99 CS423 (cotter) 8

OO Structure(audio clip)

Playw

hatever...

Record

Stop

Wave Data

Characteristics

Current track

Page 9: Java  Outline

CSTP FS99 CS423 (cotter) 9

OO vs. Procedures

Global Data

functionfunction function

function

Play

whatever...

Record

Stop

Wave Data

Characteristics

Current track

Audio Player

Play clip

record clip

stop

Page 10: Java  Outline

CSTP FS99 CS423 (cotter) 10

OO Concepts

• Inheritance– Integer

– Myinteger (with min and max fields)

• Method Overloading– public String(char value[]);

– public String(char value[], int offset, int count);

• Polymorphism– public int hashCode();

Page 11: Java  Outline

CSTP FS99 CS423 (cotter) 11

OO Class Relationships

• use (call a method, etc.)• containment (“has-a”)• inheritance (is-a”)

Page 12: Java  Outline

CSTP FS99 CS423 (cotter) 12

OO Structure

• class– data

• public

• private

– methods• constructor

• destructor

• others

Page 13: Java  Outline

CSTP FS99 CS423 (cotter) 13

Java Structure

class HelloApplication { public static void main (String argv[]) { String message[] = new String[2];

message[0] = "Welcome to CS490D"; message[1] = "The subject is JAVA!";

System.out.println (message[0]); System.out.println (message[1]); }}

Page 14: Java  Outline

CSTP FS99 CS423 (cotter) 14

Java Support Environments

• JDK 1.0.2, JDK 1.1.4, JDK 1.2.2• Borland JBuilder• Semantic Cafe

– just-in-time compiler

• Visual J++• etc.

Page 15: Java  Outline

CSTP FS99 CS423 (cotter) 15

Java Info Sources

• http:/java.sun.com– The home for Java

• http://www.gamelan.com/– central repository for info

• MANY others.

Page 16: Java  Outline

CSTP FS99 CS423 (cotter) 16

Java Language Structure - Packages (1.0.2)

• java.lang - basic classes (objects, strings, threads, etc.)• java.io - stream mgmt for files, strings, other sources• java.util - time, rand, generic data struct..• java.net - URLs, TCP, UDP, IP, binary to text• java.awt - manages user interface components• java.awt.image - manage image data• java.awt.peer - platform specific implementation links• java.applet - Applet class, interfaces to resources

Page 17: Java  Outline

CSTP FS99 CS423 (cotter) 17

java.lang

• Object• Process• Runtime• Thread• Math• String• Integer• etc……

Page 18: Java  Outline

CSTP FS99 CS423 (cotter) 18

java.lang.Object

public class java.lang.Object

{

// Constructors

public Object(); §1.12.1

// Methods

protected Object clone(); §1.12.2

public boolean equals(Object obj); §1.12.3

protected void finalize(); §1.12.4

public final Class getClass(); §1.12.5

public int hashCode(); §1.12.6

public final void notify(); §1.12.7

public final void notifyAll(); §1.12.8

public String toString(); §1.12.9

public final void wait(); §1.12.10

public final void wait(long timeout); §1.12.11

public final void wait(long timeout, int nanos); §1.12.12

}

Page 19: Java  Outline

CSTP FS99 CS423 (cotter) 19

java.lang.integer

public final class java.lang.Integer extends java.lang.Number (I-§1.11){ // Fields public final static int MAX_VALUE; §1.8.1 public final static int MIN_VALUE; §1.8.2

// Constructors public Integer(int value); §1.8.3 public Integer(String s); §1.8.4

Page 20: Java  Outline

CSTP FS99 CS423 (cotter) 20

java.lang.integer

// Methods public double doubleValue(); §1.8.5 public boolean equals(Object obj); §1.8.6 public float floatValue(); §1.8.7 public static Integer getInteger(String nm); §1.8.8 public static Integer getInteger(String nm, int val); §1.8.9 public static Integer getInteger(String nm, Integer val); §1.8.10 public int hashCode(); §1.8.11 public int intValue(); §1.8.12 public long longValue(); §1.8.13 public static int parseInt(String s); §1.8.14 public static int parseInt(String s, int radix); §1.8.15 public static String toBinaryString(int i); §1.8.16 public static String toHexString(int i); §1.8.17 public static String toOctalString(int i); §1.8.18 public String toString(); §1.8.19 public static String toString(int i); §1.8.20 public static String toString(int i, int radix); §1.8.21 public static Integer valueOf(String s); §1.8.22 public static Integer valueOf(String s, int radix); §1.8.23}

Page 21: Java  Outline

CSTP FS99 CS423 (cotter) 21

Building Java Applications Using Java Development Kit

• Get a copy of the JDK (java.sun.com, etc.)• Install the development kit (tools and classes)• Create MyApp.java source file

– text editor (notepad, etc.)

– winedit, Café, etc.

• Compile .java file to create .class file– javac MyApp.java

• Run application (.class file) through java VM– java MyApp

Page 22: Java  Outline

CSTP FS99 CS423 (cotter) 22

Sample Java App

G:\Data\Java\MyHelloApp>type MyHelloApp.javaclass MyHelloApp { public static void main (String argv[]) { String message[] = new String[2]; message[0] = "Welcome to CS423"; message[1] = "The subject is JAVA!";

System.out.println (message[0]); System.out.println (message[1]); } }

Page 23: Java  Outline

CSTP FS99 CS423 (cotter) 23

Sample Java App

G:\Data\Java\MyHelloApp>javac MyHelloApp.java

G:\Data\Java\MyHelloApp>java MyHelloAppWelcome to CS423The subject is JAVA!

G:\Data\Java\MyHelloApp>

Page 24: Java  Outline

CSTP FS99 CS423 (cotter) 24

Add Interaction with User

class ParmApplication{public static void main (String argv[]) { int i; if (argv.length == 0) { System.out.println (""); System.out.println (" Put parameters on the " + "command line. Here is the syntax:");

Page 25: Java  Outline

CSTP FS99 CS423 (cotter) 25

Add Interaction with User

System.out.println ("");System.out.println ("java ParmApplication Parm0 " + "Parm1 Parm2 [...]");System.out.println ("");System.exit (1);}System.out.println ("");System.out.println (" " + argv.length + " string parameter(s) entered:");

Page 26: Java  Outline

CSTP FS99 CS423 (cotter) 26

Add Interaction with User

for (i = 0; i < argv.length; i++) { System.out.println

( " Parm #" + i + ": --->" + argv[i] + "<---" ); } System.out.println (""); } }

Page 27: Java  Outline

CSTP FS99 CS423 (cotter) 27

Add interaction with user

G:\ParmApplication>javac ParmApplication.java

G:\ParmApplication>java ParmApplication

Put parameters on the command line. Here is the syntax:

java ParmApplication Parm0 Parm1 Parm2 [...]

G:\ParmApplication>java ParmApplication first 2nd 35

3 string parameter(s) entered: Parm #0: --->first<--- Parm #1: --->2nd<--- Parm #2: --->35<---

G:\ParmApplication>

Page 28: Java  Outline

CSTP FS99 CS423 (cotter) 28

Get Input from User

import java.io.*;

class InputApp { InputApp () { DataInputStream dis = new DataInputStream (System.in); String sIn = " "; String sOut = " "; File fIn; File fOut; FileInputStream fis; FileOutputStream fos; int iNumBytesRead; byte[] ab;

Page 29: Java  Outline

CSTP FS99 CS423 (cotter) 29

Get Input from User

System.out.println ("*-------------------------------------------*"); System.out.print ("Enter Source File Name Here: "); System.out.flush (); try {sIn = dis.readLine ();} catch (Exception e) {System.out.println ("Exception on input file name"

+ e);} System.out.print("Enter Destination File Name Here: "); System.out.flush (); try {sOut = dis.readLine ();} catch (Exception e) {System.out.println ("Exception on output file name"

+ e);}

Page 30: Java  Outline

CSTP FS99 CS423 (cotter) 30

Get Input from User

try { fIn = new File (sIn); fis = new FileInputStream (fIn); fOut = new File (sOut); fos = new FileOutputStream (fOut); ab = new byte[2048]; while ((iNumBytesRead = fis.read (ab)) != -1) { fos.write (ab, 0, iNumBytesRead); } fis.close (); fos.close (); }catch (Exception e) {System.out.println ("Exception during copy: " + e); }

Page 31: Java  Outline

CSTP FS99 CS423 (cotter) 31

Get Input from User

System.out.println ("Data copied from " + sIn + " to "+ sOut);

System.out.println ("*-------------------------------------------*");

}

public static void main (String args[]) { new InputApp (); } }

Page 32: Java  Outline

CSTP FS99 CS423 (cotter) 32

Get Input from User

G:\Data\Java\InputApp>java InputApp*-------------------------------------------*Enter Source File Name Here: books_db.txtEnter Destination File Name Here: My_list.txtData copied from books_db.txt to My_list.txt*-------------------------------------------*

G:\Data\Java\InputApp>

Page 33: Java  Outline

CSTP FS99 CS423 (cotter) 33

Java Inheritance (extension)- awt

• Object - “cosmic base class”• Component - button, listBox• Container - dialog box• Panel - “sub-window”, group of buttons, etc.• Applet - small application, web enabled• MyApplet - specific instance of an applet