Sams Teach Yourself HTML 4 in 24 Hours

Sams Teach Yourself HTML 4 in 24 Hours

By Dick Oliver

Strong Java

JavaScript and its competitors do have drawbacks and limitations. Scripting would be too slow for any high-volume data or image-processing work, and complex applications of any kind are poorly suited for direct inclusion in the text of an HTML document. After all, there are only so many lines of code you want to wade through to see the HTML itself.

When you outgrow JavaScript, does that mean you'll need to return to server-side scripting or applications programming? No. JavaScript is just the baby sister of a more robust and powerful language called Java. Like JavaScript, Java is especially designed for the Web. Also like JavaScript scripts, Java programs install and run automatically whenever a Web page is loaded. However, unlike JavaScript, Java programs are compiled into a more compact and efficient form (called bytecodes) and stored in a file separate from the Web pages that may call them.

Java also includes a complete graphics drawing library, security features, strong type checking, and other professional-level programming amenities that serious developers need. The biggest limiting factor with Java mini-applications (called applets) is that they must be small enough that downloading them doesn't delay the display of a Web page an intolerable amount of time. Fortunately, Java applets are extremely compact in their compiled form and are often considerably smaller than the images on a typical Web page.

A Java program will work equally well on both Windows and Macintosh computers. Best of all, Java's syntax is nearly identical to JavaScript's, so you can cut your teeth on JavaScript and easily move to Java when you need or want to.

You'll find many ready-to-use Java applets on the Web, and Figure 18.1 shows how to include them in a Web page. The two <applet> tags in Figure 18.1 insert two separate Java applets named Bounce.class and RnbText.class. (These class files must be placed in the same directory as the Web page.) The Bounce applet makes a graphical icon hop up and down, and the RnbText applet below it makes some text wiggle like a wave while rainbow colors flow through it. Figure 18.2 is a snapshot of these animated effects.

18fig01.gif

Figure 18.1 Java applets are prewritten programs that you place on your Web page with the <applet> tag.

18fig02.gif

Figure 18.2 The <applet> tags in Figure 18.1 insert programs for drawing a bouncing happy face and some wiggly, colorfully animated text.

The width and height attributes in the <applet> tag do just what you'd expect them to—specify the dimensions of the region on the Web page that will contain the applet's output. The <param /> tag supplies any information that a specific applet needs in order to do its thing. name identifies what information you're supplying to the applet, and value is the information itself. In this example, the RnbText applet is designed to display some text, so you have to tell it what text to display. The Bounce applet doesn't require any <param /> tag because it was designed to do just one thing, with no optional settings.

Every applet requires different settings for the name and value attributes, and most applets require more than one <param /> tag to set all their options. Whoever created the applet will tell you (usually in some kind of readme.txt or other documentation file) what name attributes you need to include and what sort of information to put in the value attributes for each name.

Share ThisShare This

Informit Network