cse 373 -- s. tanimoto java introduction 1 java a programming language for web-based computing with...

12
CSE 373 -- S. Tanimoto 1 Java A Programming Language for Web-based Computing with Graphics

Upload: jade-richard

Post on 04-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 373 -- S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics

CSE 373 -- S. Tanimoto Java Introduction

1

Java

A Programming Language forWeb-based Computing with Graphics

Page 2: CSE 373 -- S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics

CSE 373 -- S. Tanimoto Java Introduction

2

Language Features of Java

-- Garbage-collected-- Support for object-oriented programming-- Support for packages-- Compiles to intermediate code-- Intermediate code is then interpreted-- Built-in support for many data structures such as hash tables, vectors

Page 3: CSE 373 -- S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics

CSE 373 -- S. Tanimoto Java Introduction

3

Applets vs CGIDifferences:

Java supports client-side processing in Web via “Applets”

HTTP GET/POST

Web page

Apache W.S.

CGI program

Browser

HTTP GET

Java class files

Apache W.S.Browser/JVM

Applet Exec.

Client Side Server Side

Page 4: CSE 373 -- S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics

CSE 373 -- S. Tanimoto Java Introduction

4

More Features of Java

More Differences:

•Security considerations, because of its web orientation: compulsory “try” and “catch” error handling.

•Stronger typing of variables than in, say, Lisp or Perl.

•Standard graphics API’s: the AWT and Swing.

Page 5: CSE 373 -- S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics

CSE 373 -- S. Tanimoto Java Introduction

5

Influences on Java

C, C++: syntax of arithmetic and boolean expressions, need for safe pointer operations.

Smalltalk, C++, CLOS: Object orientation

Lisp: garbage collection, “bignums”

Page 6: CSE 373 -- S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics

CSE 373 -- S. Tanimoto Java Introduction

6

Java’s Web SupportApplets: Java virtual machine can run in a browser. Safe pointers avoid segmentation faults and other dangerous errors.

Security manager provides that applets don’t perform I/O to client hard disk.

Applets permitted only limited upload communication (to the originating server).

Standard networking package is provided.

Page 7: CSE 373 -- S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics

CSE 373 -- S. Tanimoto Java Introduction

7

Java’s Graphics

AWT: The Abstract Windowing Toolkit is a package providing standard classes for building GUIs.

Support for decoding GIF and JPEG image formats is built in.

Java has used two slightly different event models for user interaction: JDK 1.0 (old) and JDK 1.1 (new).

Java2D is a more advanced imaging package that’s made to work with Java 2.

Page 8: CSE 373 -- S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics

CSE 373 -- S. Tanimoto Java Introduction

8

Java’s ThreadsJava programs can contain multiple threads of control.

This can permit parallel processing.

This can permit logical separation of the program into code for concurrent processes.

Threads are especially useful in animation within an applet.

Run-time scheduling of threads is not completely platform independent.

Page 9: CSE 373 -- S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics

CSE 373 -- S. Tanimoto Java Introduction

9

Example Application

class MyFirstApplication { public static void main(String[] args) { System.out.println("Hello CSE 373"); }}

To compile on a Unix system, type:javac MyFirstApplication.java

Then to run it, type:java MyFirstApplication

Page 10: CSE 373 -- S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics

CSE 373 -- S. Tanimoto Java Introduction

10

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

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

To compile on a Unix system, type:javac MyFirstApplet.java

Then to run it, embed a reference to it in a web page...

Page 11: CSE 373 -- S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics

CSE 373 -- S. Tanimoto Java Introduction

11

Web Page with Applet Tag(works with Mozilla Firefox)

<HTML><HEAD><TITLE> A Simple Program </TITLE></HEAD><BODY><H1>So here is my first applet:<H2>

<APPLET CODE=”MyFirstApplet.class” WIDTH=150 HEIGHT=25></APPLET>

</BODY></HTML>

Page 12: CSE 373 -- S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics

CSE 373 -- S. Tanimoto Java Introduction

12

Logistics of Getting Started With Java

•Choose a place to work: Home, dorm, Math Sciences Computer Center (CSE 373’s designated lab), etc.

•If you need to, download and install JDK 1.4 using the link on our syllabus page.

•If you need to, download and install Eclipse from www.eclipse.org.