HTML

HTML

Animation

ActiveX

JAVA

VRML

CGI

ISAPI

Security

Grafman




Gotchas | Creating | Compiling | HTML

Java Overview

Java is a portable language created by Sun that creates distributable, tokenized objects. If you need to write programs that are transparently portable across the Internet, Java is the way to go.

Unlike portable scripting languages like PERL or TCL, Java is a complete object-oriented programming language that may be interpretted, tokenized or compiled -- it will even run natively on custom Java chips.

Java is very similar to C++, with the major difference being that Java does not use pointers -- it uses named objects -- which makes it better suited for running on distributed, internet environments. Java is currently missing digital object signing, but a draft proposal is under way to add it. Until encryption and digital signing is available on all common Java platforms, distributable Java Applets will be limited in functionality, for security reasons.

So what is the major advantage of Java over C++ or any other object-oriented language? Its portable class library. No other class library is so extensive or available on so many platforms. Its class library provides threading, URL retrieval, image handling, 2D graphics, 3D modeling... Java makes portable pragramming as easy as native C++.

Java is also the standard language adopted by the Virtual Reality Modeling Language to add behaviors to 3D objects.


Java Gotchas

As in any programming language, programmers need to watch out for memory leaks and runnaway threads. However, this is especially true with any applet that can be transparently installed on a user's machine.

A user can be cruising through a series of sites that have Java applets, and if several applets keep themselves loaded and fail to release memory, or if they continue to process intensive threads, the user's performance will seriously degrade.

Since Java makes it easy for any novice programmer to post applets on the Web, and since the user is often unaware that an applet has been loaded (much less which applet might be causing their performance problems), it is very critical for programers to watch out for these issues, and for users to be careful regarding what applets they allow to be loaded on their computers.


Creating Java Applets

The best way to see Java applets in action is to get Netscape's Navigator 3.0 and cruise around some Java sites.

The easiest way to start working with Java is to get the free Java Developer's Kit and poke around in its sample code. If you are familiar with C++, this will be pretty straight-forward.

If you are ready to start serious development of Java applications, Symantec's Cafe' provides an integrated Java development environment with a runtime debugger.


Compiling Java Applets (Windows)

If you are using an early version of Java Development Kit on Windows, there are few things to keep in mind:

After downloading and installing the JDK, set your PATH to include the java\bin directory and the CLASSPATH environment variable to the java\lib directory.

Then use the javac compiler to tokenize your application/applet: javac Applet.java, where Applet.java is the source file name.

Note: while the compiler is not case sensitive in finding your source file, it will fail if the case doesn't match the public name defined in the source -- after it has spent several minutes compiling your applet!

Remember to use getCodeBase and getDocumentBase to find auxiliary files, if they are not guaranteed to be in the same directory as the referring URL calling the applet.


Embedding Java Applets in HTML

Java applets are exposed in Java-capable browsers via the APPLET HTML tag:

    <APPLET CODE="JavaApplet.class" WIDTH=200 HEIGHT=150></APPLET>

The applet code (JavaApplet.class) and any auxiliary files are assumed to be in the same directory/folder as the HTML document refering to it.

Here's a more complex example of an APPLET tag:

    <APPLET CODEBASE="http://www.graphcomp.com/java/spin/"
    CODE="Spin.class" WIDTH=150 HEIGHT=150>
    <PARAM NAME="model" VALUE="models/dome.obj">
    <BLOCKQUOTE>
    <HR>
    If you upgrade your web browser to one that supports Java, you will see a spinning dome here.
    <HR>
    </BLOCKQUOTE>
    </APPLET>

CODEBASE indicates the location of the applet's code and the PARAM tag passes parameters to the applet. The BLOCKQUOTE tag is ignored by Java-compliant browsers, but displayed by browsers that do not support Java.

The complete syntax for the APPLET tag is:

    '<' 'APPLET'
      ['CODEBASE' '=' codebaseURL]
      'CODE' '=' appletFile
      ['ALT' '=' alternateText]
      ['NAME' '=' appletInstanceName]
      'WIDTH' '=' pixels 'HEIGHT' '=' pixels
      ['ALIGN' '=' alignment]
      ['VSPACE' '=' pixels] ['HSPACE' '=' pixels]
    '>'
    ['<' 'PARAM' 'NAME' '=' appletAttribute1 'VALUE' '=' value '>']
    ['<' 'PARAM' 'NAME' '=' appletAttribute2 'VALUE' '=' value '>']
    . . .
    [alternateHTML]
    '</APPLET>'
'CODEBASE' '=' codebaseURL
    This optional attribute specifies the base URL of the applet -- the directory that contains the applet's code. If this attribute is not specified, then the document's URL is used.
'CODE' '=' appletFile
    This required attribute gives the name of the file that contains the applet's compiled Applet subclass. This file is relative to the base URL of the applet. It cannot be absolute.
'ALT' '=' alternateText
    This optional attribute specifies any text that should be displayed if the browser understands the APPLET tag but can't run Java applets.
'NAME' '=' appletInstanceName
    This optional attribute specifies a name for the applet instance, which makes it possible for applets on the same page to find (and communicate with) each other.
'WIDTH' '=' pixels 'HEIGHT' '=' pixels
    These required attributes give the initial width and height (in pixels) of the applet display area, not counting any windows or dialogs that the applet brings up.
'ALIGN' '=' alignment
    This required attribute specifies the alignment of the applet. The possible values of this attribute are the same as those for the IMG tag: left, right, top, texttop, middle, absmiddle, baseline, bottom, absbottom.
'VSPACE' '=' pixels 'HSPACE' '=' pixels
    These option attributes specify the number of pixels above and below the applet (VSPACE) and on each side of the applet (HSPACE). They're treated the same way as the IMG tag's VSPACE and HSPACE attributes.
'<' 'PARAM' 'NAME' '=' appletAttribute1 'VALUE' '=' value '>' . . .
    This tag is the only way to specify an applet-specific attribute. Applets access their attributes with the getParameter() method.

Note: the <APPLET> tag is being obsoleted by the <OBJECT> tag, which is SGML-comliant and is more flexible.


Gotchas | Creating | Compiling | HTML

© Copyright 1996 - Grafman Productions - ALL RIGHTS RESERVED
Grafman Productions