12.1 Applets and ObjectsApplets represent a shift in the basic model of web communications. In most other web applications, servers perform most of the computational work, client browsers being not much more than glorified terminals. With applets, web technology shifts to the client, distributing some or all of the computational load from the server to the client computer and its browser. Applets also represent a way of extending a browser's features without forcing users to acquire new browsers, as is the case when developers implement new tag and attribute extensions to HTML. Nor do users have to acquire and install a special application, as is required for helper or plug-in applications.[1] This means that once users have a browser that supports applets, you can deliver applets directly to the browser, including display and multimedia innovations.
12.1.1 The Object ModelJava-based applets — web page-referenced programs retrieved from a network server and executed on the user's client computer — are an example of what the HTML 4 and XHTML standards call inclusions. As with images, the browser first loads the HTML document, then examines it for inclusions — additional, separate, and discrete content that is to be handled by the client browser. A GIF image is one type of inclusion. A .wav sound file, an MPEG movie, and a Java-based clock program are other types. The HTML 4 and XHTML standards generally call the inclusion contents objects. In fact, in your document you may identify and load nearly any object file over the network through a universal <object> tag, which we discuss in detail in Section 12.2.1. Once it has been downloaded, the standards dictate that the browser somehow render the object, by internal or external mechanisms. Otherwise, plug-ins and other helper applications may provide the necessary rendering mechanism. Internet Explorer, for example, has its internal resources play an AVI movie, whereas Netscape relies upon some third-party software, such as RealPlayer, to reproduce the movie. 12.1.1.1 The applet modelWith Java applets, the browser sets aside a portion of the document display space. You may control the size and position of this display area; the applet controls what is presented inside. The applet is software, an executable program. Accordingly, besides providing a display space, the browser, in tandem with the client computer environment and resources, provides the applet with a runtime environment called a virtual machine. During execution, Java applets have access to a restricted environment within the user's computer. For instance, applets have access to the mouse and keyboard and may receive input from the user. Depending on the security policy in place, they may initiate network connections and retrieve data from other servers on the Internet. In sum, applets are full-fledged programs, complete with a variety of input and output mechanisms, along with a full suite of network services. Several applets may be placed in a single document; they all execute in parallel and may communicate with each other. While the browser may limit their access to its computer system, applets have complete control of their virtual environment within the browser. 12.1.1.2 The applet advantageThere are several advantages of applets, not the least of which is providing more compelling user interfaces within a web page. For instance, an applet might create a unique set of menus, choices, text fields, and similar user-input tools different from those available through the browser. When the user clicks a button within the applet's interaction/display region, the applet might respond by displaying results within the region, signaling another applet, or even by loading a completely new page into the browser. We don't mean to imply that the only use of applets is to enhance the user interface. An applet is a full-fledged program that can perform any number of computational and user-interactive tasks on the client computer. An applet might implement a real-time video display, perform circuit simulation, engage the user in a game, provide a chat interface, and so on. 12.1.1.3 Using applets correctlyAn applet is nothing more than another tool you can use to produce compelling and useful web pages. Keep in mind that an applet uses computational resources on the client to run and therefore places a load on the user's computer. It can degrade system performance. Similarly, if an applet uses a lot of network bandwidth to accomplish its task (a real-time video feed, for example), it may make other network communication unbearably slow. While such applications are fun, they do little more than annoy your target audience. To use an applet correctly, balance the load between the browser and the server. For each page, decide which tasks are best left to the server (forms processing, index searches, and the like) and which tasks are better suited for local processing (user-interface enhancements, real-time data presentation, small animations, input validation, and so on). Divide the processing accordingly. Remember that many users have slower network connections and computers than you do, and design your applets to satisfy the majority of your audience. Used the right way, applets seamlessly enhance your pages and provide a satisfying experience for your audience. Used improperly, applets are just another annoying bandwidth waster, alienating your users and hurting your pages. 12.1.1.4 Writing appletsCreating Java applets is a programming task, not usually a job for the HTML or XHTML author. For details, we recommend that you consult any of the many Java programming texts, including those from O'Reilly. Developed by Sun Microsystems, Inc. of Mountain View, CA, Java supports an object-oriented programming style wherein classes of applets can be used and reused to build complex applications. One would think that applets written in the same language should run in any browser that supports Java. As is so often the case, reality is more complex. Until Netscape 6 and Internet Explorer 6, browsers included their own Java Virtual Machines ( JVMs), and their implementations, especially Microsoft's, could be quirky. Certain Microsoft implementation decisions in Internet Explorer 4 and earlier caused some valid Java applets to fail when running. Microsoft fixed these problems with Internet Explorer Version 5 but, because of its lawsuit with Sun, chose not to include a JVM in Internet Explorer 6.[2] Although this may sound like bad news for applets, in fact Internet Explorer 6 prompts you to download Microsoft's JVM. Running a Java applet for the first time is not transparent in Internet Explorer 6, but after the initial installation, Java support is available. Netscape 6 includes Sun's Java Plug-in, which provides the only way to get support for the latest version of Java ( Java 2 Standard Edition 1.4). Users of either browser can install the Java Plug-in to get state-of-the-art Java support. As an HTML author collaborating with Java developers, you should assume that most browsers, unfortunately, have outdated Java support.
We should take this opportunity to also mention ActiveX, an alternative executable content technology available from Microsoft. ActiveX is proprietary, closely coupled with various versions of Microsoft Windows, and works only when used with Internet Explorer. ActiveX controls (as they are called) run on versions of Internet Explorer targeted to various versions of Windows, but a single ActiveX control will not run on these different versions without recompilation. This is in contrast with Java applets; a single Java applet can be written and compiled once and immediately run on a broad range of browsers and operating systems. ActiveX also presents an unacceptably high security risk to any user whose browser supports ActiveX technology.[3] It is ridiculously easy to penetrate and damage a computer running a browser that allows ActiveX applets to be executed. For this reason, we cannot recommend ActiveX as a viable applet implementation technology and we go so far as to recommend that users disable ActiveX capability within their browsers — specifically, Internet Explorer.
|