Click here for a Gateway computer deal!

PC Magazine

  PC Tech

Java Archives in Java 1.2

Introduction

Working With Java Archive Files

Using Archived Applications and Applets

Bye-Bye, <applet>, Hello, <object>

Figure: Java Archive Commands



X10.com - The SuperSite for Home Automation!

NextCard Internet Visa - Apply Now

 
  Categories
Programming

Java Archives in Java 1.2
Bye-Bye, <applet>, Hello, <object>

Continued from Using Archived Applications and Applets

Under HTML 4.0, the <OBJECT> tag is replacing the <APPLET> tag as the preferred way to add applets to a Web page. The <OBJECT> tag is a multipurpose tag designed to provide a ready upgrade path for current and future types of media. A general-purpose tag for various types of media makes a lot of sense. After only a few years of Web development, there are already many different media-related tags that serve essentially the same purpose.

In fact, the single <OBJECT> tag is meant to replace the <IMG> tag for images, the <APPLET> tag for applets, the <IFRAME> tag for internal frames, and the <EMBED> tag for embedded objects.

When you use the <OBJECT> tag, you usually need to tell the browser what type of code the object refers to with the CODETYPE attribute. The code type for Java applets and applications is application/java. The code type for Java archives is application/java-archive. If you've worked with Web-based content types before, you know that application/java and application/java-archive are MIME (Multipurpose Internet Mail Extensions) types and that browsers often use the MIME type to determine how to handle various types of information.

Another important difference is that the CODE attribute of the <APPLET> tag is not available. In its place, the <OBJECT> tag uses an attribute called CLASSID, which specifies the URI (Uniform Resource Identifier) for the applet. URIs are a bit different from URLs. With URIs, you start by telling the browser the protocol or language, and then you identify the structure to take action on. To separate the protocol/language from the structure of the URI, you use a colon, as in protocol:structure.

With Java, the protocol/language for the URI is always specified as java, but the action you take depends on how you are using the applet in your Web page. If you want to invoke an applet's start() method directly, you tell the browser the path to follow to the start() method, which is normally program.start:

<OBJECT CODETYPE="application/java"
CLASSID="java:program.start"
WIDTH="250" HEIGHT="250">
</OBJECT>

If you want to invoke a specific Java class within an applet, you can specify the class. In the following example, the applet's main class is called custom.class, and this class is specified after the java: designator:

<OBJECT CODETYPE="application/java-archive"
CLASSID="java:custom.class"
WIDTH="300" HEIGHT="300">
</OBJECT>

Before you look forward to saying bye-bye to the <APPLET> tag and its cousins, you should know that it will be a while before you'll be able to use the <OBJECT>tag exclusively in your Web pages. The reason for this is that older browsers don't understand the <OBJECT> tag and won't know how to display and run your applets or other embedded objects.

For backward compatibility, insert the <APPLET> tag between the begin <OBJECT> tag and the end <OBJECT> tag. Be sure that the <APPLET> tag immediately follows the begin <OBJECT> tag. In the following example, if the browser can't use the <OBJECT> tag, the browser tries to use the <APPLET> tag:

<OBJECT CODETYPE="application/java-archive"
CLASSID="java:custom.class"
WIDTH="300" HEIGHT="300">
</APPLET CODE="custom.class"
ARCHIVE="myclasses.jar"
WIDTH="300" HEIGHT="300">
</APPLET>
</OBJECT>

On the Web, where every bit and second counts, bundling applet files into a compressed archive really does make a difference. Now that you can launch a Java archive with a simple click, we should start to see a lot more applications for our desktops.

Next: Figure: Java Archive Commands

Published as Internet Builder in the 2/23/99 issue of PC Magazine.

 
 SPONSORED LINKS
@Backup   Your Solid Online Backup Plan. Download Now.
Services   9c/MINUTE LONG DISTANCE, 5c/MINUTE ON SUNDAYS!
STORAGE   Quantum means non-stop business, 24 hours a day
Software   X10.com -- The SuperSite for Home Automation
Books   Bargain Books up to 90% off at barnesandnoble.com
 ZDNET FEATURED LINKS
Downloads   Check out the best new downloads in Reviewer's Raves
Bargains!   Shop the Basement for best buys on computer products
Free Help   Got computing questions? ZDHelp has all the answers!
 MAGAZINE OFFERS
Free Offer   Get a FREE SUBSCRIPTION to Inter@ctive Week

TOP
Copyright (c) 1998 Ziff-Davis Inc.