SCOUG Java Programming Class 2

Outline


Class 1 Review


Class 1 Samples


Execution Environment


Program Types

Application

A Java classfile can be executed via the interpreter as a standalone program provided it contains a main method. This method:

Typical definition:

   public static void main(String args[]) {
   ...
   }

 

Applet

A Java class can be embedded in an HTML document (or executed by the Applet viewer) provided it defines its public class to be an extension of the Applet class. Several methods will typically be subclassed:

Normally an applet will have restrictions on its ability to access local machine resources.

To invoke an applet from an HTML document, use the APPLET tag. Parameters can be made available to the applet by using the PARAM tag and can be accessed within the applet by using the getParameter method.

Sample HTML:

<applet code="myapplet.class" width=300 height=100>
<param name="First" value="this is the first parameter">
<param name="Font" value="TimesRoman, BOLD, 24">
</applet>

Sample code to reference the parameters:

String paramFirst, paramFont;
...
paramFirst = getParameter("First");
paramFont  = getParameter("Font");

 

It is possible to write a classfile that can be executed either as an application or as an applet. To do so, define the class as an extension of Applet but also include a main method. If the class attempts to access local machine resources, this will fail if it is being run as an applet.


Base Packages

lang

Modifier

Name

Extends

class

Boolean

 

class

Character

 

class

Class

 

abstract

ClassLoader

 

class

Compiler

 

class

Double

Number

class

Float

Number

class

Integer

Number

class

Long

Number

class

Math

 

class

Number

 

class

Object

 

abstract

Process

 

class

Runtime

 

abstract

SecurityManager

 

class

String

 

class

StringBuffer

 

class

System

 

class

Thread

 

class

ThreadGroup

 

class

Throwable

 

interface

Cloneable

 

interface

Runnable

 

 

util

Modifier

Name

Extends

class

BitSet

 

class

Date

 

abstract

Dictionary

 

class

Hashtable

Dictionary

class

Observable

 

class

Properties

Hashtable

class

Random

 

class

Stack

Vector

class

StringTokenizer

Enumeration

class

Vector

implements Cloneable

interface

Enumeration

 

interface

Observer

 

 

applet

Modifier

Name

Extends

class

Applet

 

interface

AppletContext

 

interface

AppletStub

 

interface

AudioClip

 

 


Reference


 Java and JDK as referenced herein are protected by the following copyright notices:

(c) Copyright Sun Microsystems Inc, 1992-1997. All rights reserved.

(c) Copyright IBM Corporation, 1996-1997. All rights reserved.

The JDK is based in part on work of the Independent JPEG grouip.

The Java (tm) technology is owned and exclusively licensed by Sun Microsystems Inc. Java (tm) is a trademark of Sun Microsystems Inc in the U.S. and other countries.