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

Introduction to Java

  • Upload
    hedwig

  • View
    16

  • Download
    0

Embed Size (px)

DESCRIPTION

Introduction to Java. Yin-Hsong Hsu and Yen-Cheng Chen 1998. History of Java. Green project funded by Sun for intelligent consumer electronic devices announced at May 23, 1995 experiences from CE so many kinds of machines, portability simple no hard disk => network download security. - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to Java

Introduction to Java

Yin-Hsong Hsu and Yen-Cheng Chen 1998

Page 2: Introduction to Java

2

History of Java

Green project funded by Sun for intelligent consumer electronic devices

announced at May 23, 1995experiences from CE

so many kinds of machines, portability simple no hard disk => network download security

Page 3: Introduction to Java

3

Java

Java: An Object-Oriented Programming Language for the Internet.

A Better C++-Like Language object-oriented, distributed, interpreted, multi-threaded,

secure, no pointers, garbage collection,... Platform-independent

Java programs are compiled into bytecodes, which can be run on Java Virtual Machine.

Java Applets/Servlets: small Java programs executed in WWW browsers/servers.

- “Write Once, Run Everywhere & Reuse Everywhere”

Page 4: Introduction to Java

4

Java

SimpleObject-orientedDistributedInterpretedRobustSecureArchitecture-neutral

PortableHigh performanceMultithreadedDynamic

Page 5: Introduction to Java
Page 6: Introduction to Java

6

Java Applet vs. Java Application

Applet A Java program that runs inside a Java-enabled

Web Browser

Application A stand-alone Java program

Page 7: Introduction to Java

7

How Java Program Being Executed

ApplicationSource Code

Byte Code

Interpretation

Compile javac prog.java

Interpret by a virtual machine

Page 8: Introduction to Java

8

How Java Program Being Executed

Applet

Source Code

Byte Code

HTML

compile

Browserwith

Virtual Machine Load Bytecode

JIT: Just In Time Compiler

Page 9: Introduction to Java

9

Programming Environment

Sun’s JDK (public) javac java jdb

Symantec Visual CaféMicrosoft Visual J++Borland JBuilderIBM VisualAgeSybase PowerJ

Page 10: Introduction to Java

10

First Java Application - Hello World

Code : HelloWorldApp.java

compile to bytecode “HelloWorldApp.class”execute the bytecode

class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); }}

Page 11: Introduction to Java

javac HelloWorldApp.java Compile HelloWorldApp.java to HelloWorldApp.class

java HelloWorldApp Interpret HellowWorldApp.class

Page 12: Introduction to Java

12

The anatomy of a Java application

Comments in Java Code C, C++, and /** … */

defining a classthe main() method

modifiers: public static and void arguments to the main method

using classes and objects class variables versus instance variables

Page 13: Introduction to Java

13

First Java Applet - Hello World

Code: HelloWorld.java

compile to bytecode : HelloWorld.class

import java.applet.Applet;import java.awt.Graphics;

public class HelloWorld extends Applet { public void paint(Graphics g) { g.drawString("Hello world!", 50, 25); }}

Page 14: Introduction to Java

14

Running an Applet

HTML file : xx.html <APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>

The Applet tag< applet code=class width=nn height=nn codebase=dir name=n align=str vspace=nn hspace=nn>

<param name=pn1 value=pv1><param name=pn2 value=pv2>...</applet>

Page 15: Introduction to Java

15

The anatomy of a Java applet

importing classes and packagesdefining an Applet subclassimplementing Applet methods

Page 16: Introduction to Java

16

What Applets Can Do?

Applets can usually make network connections to the host they came from.

Applets running within a Web browser can easily cause HTML documents to be displayed.

Applets can invoke public methods of other applets on the same page.

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.

Page 17: Introduction to Java

17

What Applets Can’t Do?

An applet cannot load libraries or define native methods. It cannot ordinarily read or write files on the host that's

executing it. It cannot make network connections except to the host that it

came from. It cannot start any program on the host that's executing it. It cannot read certain system properties. Windows that an applet brings up look different than

windows that an application brings up.

Page 18: Introduction to Java

18

Java Core API

Included in JDKJava classes/packages:

Data manipulation & processing. AWT (Abstract Windowing Toolkit). I/O. Networking. Security. JDBC (Java Database Connectivity) JavaBeans RMI (Remote Method Invocation). Object Serialization

Page 19: Introduction to Java

19

JDK (Java Development Kit)

Page 20: Introduction to Java

20

Java Foundation Classes (JFC, swing)

Page 21: Introduction to Java

21

Java Family

Page 22: Introduction to Java

22

Java Security

Page 23: Introduction to Java

23

Page 24: Introduction to Java

24

Page 25: Introduction to Java

25

Page 26: Introduction to Java

26

Page 27: Introduction to Java

27