PersonalJava targets non-desktop computers

Expert offers key tips to help make your PC-savvy applets scale to consumer devices

If you're interested in designing Java applets for a variety of computer devices -- not just desktops, but handheld gadgets, Web-enabled televisions and telephones, and specialized devices for vertical industries -- you've probably realized that it takes a lot more to conform to the "Write Once, Run Anywhere" philosophy than just writing 100% pure Java code and dealing with the numerous idiosyncrasies the popular Java virtual machines found on desktop operating systems and within popular Web browsers. It's a tricky task, but you must plan ahead for all the devices that will be running your Java applets, now and in the future, and design an applet that is simultaneously intuitive, clear, and efficient on all of them. At the March 1998 JavaOne Java Developer Conference, Sun Microsystems staff engineer Herb Jellinek provided an overview and extensive outline of helpful tips and techniques for designing scalable applets that run effectively on consumer devices and desktop computers alike.

First, it's probably best to know what to avoid when designing your applet. As a general rule, developers should "eschew complexity," Jellinek says. For instance, applets with a lot of windows are a no-no; this includes frames and dialogs -- both modal and non-modal. Also, avoid nested and cascaded menus. Although you personally may prefer a nested-menu interface, your code should be driven by the preferences of the intended users, many of whom may find nested menus confusing and irritating. If you need to represent a hierarchy of selections, do it one panel at a time. What about cursors and scrollbars? Although using a cursor to indicate status is a clever hack, not all devices have them -- and even if they do, they might not be writeable. Scrollbars should scroll only vertically. Users are used to scrolling up and down (within Web pages, word-processed documents, e-mail messages, etc.); horizontal scrolling seems counterintuitive (and often tedious) to most people.

Now that you know the top "don'ts" as described by Jellinek, consider a few things he recommends you should do when designing scalable applets. Implementing single-level menus and walking a user through a process one panel at a time works better than relying on nested menus. If this seems too onerous, remember the last time you followed the straightforward instructions of a step-by-step wizard. Showing status graphically is preferable to using a cursor, and ScrollPanes (part of JDK 1.0) doesn't require an input mechanism.

The PersonalJava platform lends itself well to conforming to these basic dos and don'ts. As a Java Application Environment optimized for Java-enabled devices, PersonalJava is designed specifically for resource-limited environments and upward-compatibility to standard Java.

Jellinek advises developers of PersonalJava applets to carefully consider the design issues surrounding input and output devices. Beyond computer mice, useful input devices include joysticks, touchscreens, virtual keyboards, arrow or cursor keys, single buttons and levers, and speech recognition -- a welcome option for those suffering from carpal tunnel syndrome. Such unconventional input devices require special considerations; for instance, it would be extremely inefficient to require users to double-click choices on a touchscreen, and impossible to freely drag and resize a boxed area with an arrow or cursor that moves in only one dimension.

Good design for output devices require a similar "thinking outside the box" approach, but coming from the opposite direction. Most users of consumer devices won't have access to the high-resolution computer monitors that developers and computer users enjoy. The use of televisions, LCDs, tiny PDA displays, and specialized gadget readouts force developers to consider such techniques as using only horizontal lines and an even number of pixels, drastically reducing the color palette (in some cases to two shades: dark and light), and designing images and text to appear only in the "safe viewing zone" of a television screen -- the area of a screen that is guaranteed to be viewed by any viewer, regardless of the individual size and model of television.

If you're a seasoned Java developer and are transitioning to PersonalJava or to designing applets for non-desktop devices, remember that the resources you're used to having are now limited. Don't get obsessed with displaying images; compared to text, images are actually quite large in byte size. If your device allows you to use images at all, consider using URL-based images instead of offscreen ones and call "disposed()" as early as possible to dump the images no longer needed. If you employ animation, use automated double-buffering instead of a frame-by-frame copy onto the screen to save memory, as well as the Timer API (part of the PersonalJava platform) to save threads instead of spawning one thread after another, which requires costly growing heaps to paint new frames.

Other resources that may be limited in the consumer device realm include garbage collection and allocation. To prevent problems related to such limitations, use the empty object "null:" as often as possible, and "flush" and "dispose" to liberate Java memory from, say, an image. And think ahead: What are the most popular objects in the applet? Anticipate these objects and allocate them once at the beginning.

Here are a few more useful tips:

  • Trim "textarea"s. This includes text areas for logs and histories of messages. If messages are irrelevant, get rid of them. Keep messages limited to 50 -- perhaps 100 at the most.
  • Avoid "news" whenever possible.
  • Keep your hashtables clean and efficient by limiting them to 100 elements.
  • Use finalizers wherever possible.

Bearing in mind that non-desktop computer devices are gaining popularity and usefulness, it's a good idea to start thinking about where your Java applets may end up in the not-too-distant future. These and other techniques for low-resource-consumption design may come in handy for Java developers in a wide variety of industries.

A 10-year veteran of the Internet, Mariva H. Aviram is an Internet consultant and writer covering the computer industry. Mariva's published works include articles in c|net, NetscapeWorld, and InfoWorld. Recently, Mariva wrote the XML For Dummies Quick Reference, which is pending publication by IDG Books Worldwide. For more information, visit

Learn more about this topic

  • Sun's PersonalJava page
  • Sun's About PersonalJava page
  • Patrick Chan's JavaOne '96 presentation, "Developing Real World Applets," discusses in-depth technical strategies of creating real-world applets versus applications. (Adobe Acrobat/pdf document)