Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Reduce the launch time of your applets: Store them on client machines

Tired of those slow applet downloads? Here's how to speed things up!

  • Print
  • Feedback
Launching a Java applet over a dial-up Internet connection can take tens of seconds or even minutes. While there are many things an applet designer can do to deal with this problem (see Resources), the sheer number of bytes that must be downloaded provides an upper limit on how fast any given applet can launch. One solution is to rewrite your applet as a Netscape plug-in. Unfortunately, this means you must support different binary versions of your plug-in for different machine architectures. Another approach is to write an applet in Java but store that applet on your clients' machines, much like a Netscape plug-in. With this approach, you retain most of Java's "write once, run anywhere" benefits, while getting most of the speed benefits of a plug-in.

This article shows you how to store your applets on client machines. It covers clients that aren't running Java, clients that have Java but don't have your applet installed on their machine, and clients that already have your applet on their machine. It also explains how to keep your applets from colliding with applets that other authors have stored on your client's machine, and addresses versioning problems. Finally, it discusses the security aspect of loading applets from a hard drive instead of over the network, covering when you should and shouldn't use this technique.

The three types of clients

In order to store your applets on client machines, you must support three types of clients:

  1. Clients running non-Java-enabled Web browsers or Java-enabled browsers that have Java disabled.

  2. Clients running Java-enabled browsers that do not have your applet loaded on their hard drive.

  3. Clients running Java-enabled browsers that have your applet loaded on their hard drive.


Clients without Java
Some of your users will be running non-Java-aware browsers or will be running Java-aware browsers with Java disabled. Without Java support they won't even know that an applet is present. To support these users, you must place text within the applet tags so that your users know something is there. The bold text in the example below demonstrates this support.

<APPLET CODE = "MyApplet.class" WIDTH=200 HEIGHT=100>
<PARAM NAME = datafile value = "data.txt">
There is a Java applet here. To use it, you need a Java aware
browser with Java enabled.

</APPLET>


HTML Example

Clients without your applet
For users with Java, your applet must detect whether the client machine has your applet loaded on its hard drive. Unfortunately, Java applets are not permitted to explicitly read to or write from the hard drive of a client machine. However, applets are permitted to use the built-in Java class loader to load classes by name. You can use this class loader to determine if your applet is installed on a client's machine by attempting to load a class that is only stored on the client's machine, not on your server. If the load succeeds, then your applet is installed. If it fails, it isn't. You will need a configuration class later (see Versioning), so use this class. The code looks like this:

  • Print
  • Feedback

Resources
  • Some other approaches to handling long applet downloads can be found in "Creating download progress bars for applets," in the December 1996 issue of JavaWorld:
    http://www.javaworld.com/javaworld/jw-12-1996/jw-12-progressbar.html
  • See also "Improving your Loading Performance" by Don Bowman in the January 1997 issue of Java Developer's Journal. Bowman discusses five approaches to the slow applet download problem:
    http://www.JavaDevelopersJournal.com
  • The limits currently put on running outside the Java runtime sandbox are changing. In Netscape 4, users have the ability to allow specified applets to access resources outside the Java sandbox.
  • From a Netscape press release:
  • MOUNTAIN VIEW, Calif. (February 24, 1997)
    "Signed Objects, which uses standard JAR (Java Archive file format), the open foundation for installing and updating signed components over the Web to allow users to designate levels of trust for applications that have been downloaded across the Net. Each application can have fine-grained levels of capabilities which the users can accept or deny. (Feature available in the next release)."
  • http://home.netscape.com/newsref/pr/newsrelease354.html
  • Netscape's Internet Foundation Classes are an example of storing Java class files on a client's hard drive, although Netscape differs in the details:
    http://home.netscape.com/eng/ifc/download.html
  • Microsoft's AFC are another example:
    http://www.microsoft.com/java/
  • Marimba Inc.'s Castanet product is described at the company's site:
    http://www.marimba.com/products/