g6dicp - lecture 27

13
chool of Computer Science & Information Technology G6DICP - Lecture 27 G6DICP - Lecture 27 Java Applets Java Applets

Upload: kristen-haynes

Post on 30-Dec-2015

31 views

Category:

Documents


1 download

DESCRIPTION

G6DICP - Lecture 27. Java Applets. Types of Java programs. Applications Standalone programs Applets Delivered over WWW to client (browser) Servlets Run on WWW server. Java Application. Local Computer. Bytecode (.class). Interpreter (java or jre). VM. Java Applet. Server. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: G6DICP - Lecture 27

School of Computer Science & Information Technology

School of Computer Science & Information Technology

G6DICP - Lecture 27G6DICP - Lecture 27

Java AppletsJava Applets

Page 2: G6DICP - Lecture 27

2

Types of Java programsTypes of Java programs

ApplicationsApplications Standalone programsStandalone programs

AppletsApplets Delivered over WWW to client (browser)Delivered over WWW to client (browser)

ServletsServlets Run on WWW serverRun on WWW server

Page 3: G6DICP - Lecture 27

3

Bytecode(.class)

Java ApplicationJava Application

Interpreter(java or jre)

VM

Local Computer

Page 4: G6DICP - Lecture 27

4

ServerBytecode(.class)

Java AppletJava Applet

Web Browser VM

Client

Page 5: G6DICP - Lecture 27

5

Java ServletJava Servlet

Web Server(eg Apache with jserv)

VM

HTML

Bytecode(.class)

Page 6: G6DICP - Lecture 27

6

Feasibility of AppletsFeasibility of Applets

Java has platform independent binariesJava has platform independent binaries

WWW is designed to be data neutralWWW is designed to be data neutral

Security is Security is thethe major issue major issue

Page 7: G6DICP - Lecture 27

7

The HTML APPLET TagThe HTML APPLET Tag

<HTML> <HEAD> <TITLE>An Applet Test</TITLE> </HEAD>

<BODY> <H1>An Applet Test</H1> <APPLET CODE=”myApplet.class" WIDTH=360 HEIGHT=250> </APPLET> </BODY> </HTML>

Page 8: G6DICP - Lecture 27

8

About AppletsAbout Applets

Applets are always graphicalApplets are always graphical Applets must be subclasses of the Applet class (Panel)Applets must be subclasses of the Applet class (Panel) The Applet container is drawn in the window of the web browser.The Applet container is drawn in the window of the web browser.

Class Applet contains the init() methodClass Applet contains the init() method Invoked automatically by a browser when a web page containing the Invoked automatically by a browser when a web page containing the

<APPLET> tag is loaded<APPLET> tag is loaded Thus main method is not needed(!) Thus main method is not needed(!)

Security issuesSecurity issues Signed Applets - full functionality of JavaSigned Applets - full functionality of Java Unsigned Applets - substantially restricted functionalityUnsigned Applets - substantially restricted functionality

Page 9: G6DICP - Lecture 27

9

A Hello World AppletA Hello World Applet

import java.awt.*;import java.applet.*;

public class demo extends Applet{ public void init() { setSize(360,250); }

public void paint(Graphics g) { g.drawString("Hello World!",50,50); }}

Page 10: G6DICP - Lecture 27

10

Typical Conversion of an Application to an AppletTypical Conversion of an Application to an Applet Make sure that all i/o goes through the AWT Make sure that all i/o goes through the AWT

interface.interface. eg use g.drawString() instead of System.out.println()eg use g.drawString() instead of System.out.println()

Remove any means for stopping the programRemove any means for stopping the program eg remove System.exit()eg remove System.exit()

Subclass Applet instead of FrameSubclass Applet instead of Frame Override the Frame.init() method, and put the Override the Frame.init() method, and put the

functionality of the applications constructor in functionality of the applications constructor in there.there.

Remove the main() method of the application.Remove the main() method of the application.

Page 11: G6DICP - Lecture 27

11

Applet Security Restrictions (1)Applet Security Restrictions (1) Applied by web browser (ie do not usually apply Applied by web browser (ie do not usually apply

in appletviewer)in appletviewer)

Cannot use native codeCannot use native code

Cannot read Cannot read somesome system properties system properties

Cannot start other programsCannot start other programs

Applet windows are clearly labelled - this cannot Applet windows are clearly labelled - this cannot be disabled or removed.be disabled or removed.

Page 12: G6DICP - Lecture 27

12

Applet Security Restrictions (2)Applet Security Restrictions (2) Cannot read or write files on the client.Cannot read or write files on the client.

No direct file access to the server (although No direct file access to the server (although network connections can be made).network connections can be made).

Network connections can only be made to the Network connections can only be made to the machine from which the applet is being served.machine from which the applet is being served.

Page 13: G6DICP - Lecture 27

13

Version IssuesVersion Issues

Classes used must be availableClasses used must be available This can be a problem with SwingThis can be a problem with Swing

Can be serious compatibility problems between Can be serious compatibility problems between software developed with a newer JDK and on software developed with a newer JDK and on earlier browser VMearlier browser VM

Modern browsers usually have a “plugin” VMModern browsers usually have a “plugin” VM Many older ones do notMany older ones do not