Introduction to Java YinHsong Hsu and YenCheng Chen

  • Slides: 27
Download presentation
Introduction to Java Yin-Hsong Hsu and Yen-Cheng Chen 1998

Introduction to Java Yin-Hsong Hsu and Yen-Cheng Chen 1998

History of Java z. Green project funded by Sun for intelligent consumer electronic devices

History of Java z. Green project funded by Sun for intelligent consumer electronic devices zannounced at May 23, 1995 zexperiences from CE yso many kinds of machines, portability ysimple yno hard disk => network download ysecurity 2

Java - “Write Once, Run Everywhere & Reuse Everywhere” z Java: An Object-Oriented Programming

Java - “Write Once, Run Everywhere & Reuse Everywhere” z Java: An Object-Oriented Programming Language for the Internet. z A Better C++-Like Language yobject-oriented, distributed, interpreted, multi-threaded, secure, no pointers, garbage collection, . . . z Platform-independent y. Java programs are compiled into bytecodes, which can be run on Java Virtual Machine. z Java Applets/Servlets: small Java programs executed in WWW browsers/servers. 3

Java z. Simple z. Object-oriented z. Distributed z. Interpreted z. Robust z. Secure z.

Java z. Simple z. Object-oriented z. Distributed z. Interpreted z. Robust z. Secure z. Architecture-neutral 4 z. Portable z. High performance z. Multithreaded z. Dynamic

Java Applet vs. Java Application z. Applet y. A Java program that runs inside

Java Applet vs. Java Application z. Applet y. A Java program that runs inside a Java-enabled Web Browser z. Application y. A stand-alone Java program 6

How Java Program Being Executed z. Application Source Code Compile javac prog. java Byte

How Java Program Being Executed z. Application Source Code Compile javac prog. java Byte Code Interpret by a virtual machine Interpretation 7

How Java Program Being Executed z. Applet HTML Source Code compile Browser with Virtual

How Java Program Being Executed z. Applet HTML Source Code compile Browser with Virtual Machine JIT: Just In Time Compiler 8 Byte Code Load Bytecode

Programming Environment z. Sun’s JDK (public) yjavac yjava yjdb z. Symantec Visual Café z.

Programming Environment z. Sun’s JDK (public) yjavac yjava yjdb z. Symantec Visual Café z. Microsoft Visual J++ z. Borland JBuilder z. IBM Visual. Age z. Sybase Power. J 9

First Java Application - Hello World z. Code : Hello. World. App. java class

First Java Application - Hello World z. Code : Hello. World. App. java class Hello. World. App { public static void main(String[] args) { System. out. println("Hello World!"); } } zcompile to bytecode “Hello. World. App. class” zexecute the bytecode 10

zjavac Hello. World. App. java y. Compile Hello. World. App. java to Hello. World.

zjavac Hello. World. App. java y. Compile Hello. World. App. java to Hello. World. App. class zjava Hello. World. App y. Interpret Hellow. World. App. class

The anatomy of a Java application z. Comments in Java Code y. C, C++,

The anatomy of a Java application z. Comments in Java Code y. C, C++, and /** … */ zdefining a class zthe main() method ymodifiers: public static and void yarguments to the main method zusing classes and objects yclass variables versus instance variables 12

First Java Applet - Hello World z. Code: Hello. World. java import java. applet.

First Java Applet - Hello World z. Code: Hello. World. java import java. applet. Applet; import java. awt. Graphics; public class Hello. World extends Applet { public void paint(Graphics g) { g. draw. String("Hello world!", 50, 25); } } zcompile to bytecode : Hello. World. class 13

Running an Applet z. HTML file : xx. html <APPLET CODE="Hello. World. class" WIDTH=150

Running an Applet z. HTML file : xx. html <APPLET CODE="Hello. World. class" WIDTH=150 HEIGHT=25> z. The Applet tag < applet code=class width=nn height=nn codebase=dir name=n align=str vspace=nn hspace=nn> <param name=pn 1 value=pv 1> <param name=pn 2 value=pv 2>. . . </applet> 14

The anatomy of a Java applet zimporting classes and packages zdefining an Applet subclass

The anatomy of a Java applet zimporting classes and packages zdefining an Applet subclass zimplementing Applet methods 15

What Applets Can Do? z Applets can usually make network connections to the host

What Applets Can Do? z Applets can usually make network connections to the host they came from. z Applets running within a Web browser can easily cause HTML documents to be displayed. z Applets can invoke public methods of other applets on the same page. z Applets that are loaded from the local file system (from a directory in the user's CLASSPATH) have none of the restrictions that applets loaded over the network do. 16

What Applets Can’t Do? z An applet cannot load libraries or define native methods.

What Applets Can’t Do? z An applet cannot load libraries or define native methods. z It cannot ordinarily read or write files on the host that's executing it. z It cannot make network connections except to the host that it came from. z It cannot start any program on the host that's executing it. z It cannot read certain system properties. z Windows that an applet brings up look different than windows that an application brings up. 17

Java Core API z. Included in JDK z. Java classes/packages: y. Data manipulation &

Java Core API z. Included in JDK z. Java classes/packages: y. Data manipulation & processing. y. AWT (Abstract Windowing Toolkit). y. I/O. y. Networking. y. Security. y. JDBC (Java Database Connectivity) y. Java. Beans y. RMI (Remote Method Invocation). y. Object Serialization 18

JDK (Java Development Kit) 19

JDK (Java Development Kit) 19

Java Foundation Classes (JFC, swing) 20

Java Foundation Classes (JFC, swing) 20

Java Family 21

Java Family 21

Java Security 22

Java Security 22

23

23

24

24

25

25

26

26

27

27