Skip to main content.

Web Based Programming Tutorials

Homepage | Forum - Join the forum to discuss anything related to programming! | Programming Resources

Java Unleashed Second Edition

Chapter 3 -- Browsing Java

Chapter 3

Browsing Java

by Bryan Morgan and Michael Morrison


CONTENTS


Java applets wouldn't be very useful without a client Web browser to run them in. Sure, we could all download applets and run them using the JDK (Java Developers Kit) applet viewer tool but that wouldn't be quite the same. Because Java applets are so dependent on quality Java-enabled Web browsers, this entire chapter explores the available Web browsers that currently offer Java support. The three big browsers that support Java as of this writing are Sun's HotJava 1.0, Netscape Navigator 3.0, and Microsoft Internet Explorer 3.0.

The HotJava 1.0 browser is actually still in pre-beta form, but it will be an important browser in the near future because it is being developed by JavaSoft. The other two Web browsers, Netscape Navigator 3.0 and Microsoft Internet Explorer 3.0, are currently battling it out over who dominates the Web client software market. This chapter doesn't bother trying to rate one browser over another because all we're concerned with is Java. Instead, you learn about what each browser has to offer in terms of Java support.

HotJava 1.0

The HotJava browser is a product of JavaSoft, the subsidiary of Sun Microsystems that is responsible for Java. It is the only Web browser that not only supports Java applets but also is actually written in Java. Although the browser market is dominated at the present time by Netscape Navigator and Microsoft Internet Explorer, HotJava stands a chance to rock the boat a little when it ships in final form.

What is now known as the HotJava product was actually introduced as a standalone Web browser back in the spring of 1995. As Java's potential was recognized by the public and its popularity skyrocketed, HotJava came to be much more than a Web browser. The HotJava product now also refers to a set of Java class libraries that simplify the creation of Internet-aware applications. The HotJava browser is provided as a showcase of these class libraries' capabilities. The HotJava class library will be available from JavaSoft as a licensable product in the near future, possibly at the release of Java 1.1.

At this time, HotJava can best be explored by downloading and installing the HotJava Web browser. You can download the HotJava browser from JavaSoft's Web site:

http://www.javasoft.com.

In the following sections, you learn about some of the features in HotJava that make it unique among other Web browsers.

HotJava Features

The HotJava Web browser supports many of the most popular browser features. More important to this discussion is its support for the execution of Java applets. HotJava also has the following features that make it somewhat unique among other browsers:

Navigating in HotJava

Figure 3.1 shows the navigation buttons available to the HotJava user.

Figure 3.1: The HotJava navigator buttons.

These buttons, from left to right, perform the following functions:

The last button bears some special mention because this feature is unique to the HotJava Web browser. HotJava features a sophisticated HTML parser that can detect errors in HTML pages. The last button on the HotJava toolbar is used to display any HTML errors found within a page.

Setting Preferences

HotJava provides a means to alter its preferences, which means that you can configure the browser display and applet security, among other things. You access these preferences by selecting Preferences from the Edit menu. The following list briefly explains the submenu items of interest available under the Preferences menu:

Figure 3.2: Contents of the Preferences/Display form.

Note
These security settings are completely browser dependent and do not rely in any way on Java or the Java virtual machine. Developers who complain that Java is too restrictive are generally misinformed (or underinformed). In general, it is the Java default implementations that are designed to be restrictive-and for good reason!

Setting View Options

HotJava's View menu contains a set of options that apply specifically to the current page being viewed. The following list briefly explains some of the more important menu items:

Figure 3.3: The HotJava Thread Monitor page.

Content and Protocol Handlers

HotJava is the only Web browser with direct support for dynamic content and protocol handlers. In case you aren't familiar with these concepts, a protocol handler is a piece of code that handles the details of transferring different types of information between a server and client across an Internet connection. A content handler takes information that has been transmitted or received with a protocol handler and determines how that information is processed.

A good example of a protocol is HTTP (HyperText Transfer Protocol), which defines the means in which hypertext documents are transferred between a Web server and client browser. Both the server and client in this case have HTTP protocol handlers that determine how the hypertext information is packaged and transferred. Likewise, an example of a content handler is the component of a Web browser that interprets and displays Web pages based on HTML content sent with the HTTP protocol. All Web browsers must support content and protocol handlers at this level.

HotJava offers a whole new level of abstraction by supporting dynamic content and protocol handlers-meaning that you can add support for new protocol and content types to the HotJava browser without getting a new version of the browser. This modularization of protocol and content types allows the structure of the Web to evolve and change without requiring significant reworking of the browser itself; if a new protocol or content type emerges, you just plug in the handler for it and go!

You learn all about writing your own content and protocol handlers in Chapter 24, "Developing Content and Protocol Handlers."

Netscape Navigator 3.0

If you are like the average Web user, chances are extremely good that you use or have used the Netscape Navigator Web browser. Netscape Navigator is by far the most popular Web browser. In fact, Netscape claims to currently control around 80 percent of the Web browser market with Navigator, although this number is no doubt dropping as Microsoft aggressively pursues Netscape with its Internet Explorer. However, one number Microsoft can't compete with at present is the number of platforms for which Navigator is available. Currently, Navigator is available for a whopping 16 different platforms including Windows 3.1, Windows 95/NT, Apple Macintosh 68K/PowerPC, and Sun Solaris, among others.

Because Navigator-and Internet Explorer, for that matter-has features similar to those discussed earlier in the HotJava Web browser, there's no need to spend a great deal of time discussing each individual feature. Instead, let's turn our attention to its support of Java and related technologies.

Java Support

The most recent version of Netscape Navigator, version 3.0, represents Netscape's most complete support for Java to date. Navigator 3.0 includes full support for both Java applets and JavaScript programs. It even supports the latest version of JavaScript (version 1.1). I guess this doesn't come as too much of a surprise considering that Netscape developed JavaScript! Fig-ure 3.4 shows Netscape Navigator 3.0 in action. You can download Netscape Navigator 3.0 from Netscape's Web site, which is located at http://www.netscape.com.

Figure 3.4: Netscape Navigator 3.0.

Even though core support for Java and JavaScript is extremely important, one of the more exciting features of Navigator is its inclusion of a just-in-time Java compiler in the Windows 95/NT version. If you aren't familiar with just-in-time compilers, they compile Java executables into native machine code on the fly to allow much faster execution speeds. For the details about just-in-time Java compilers, check out Chapter 44, "Just-in-Time Compilers."

Along with all this Java support behind the scenes, Navigator also has a nice feature not found in many other Web browsers: the Java console (see Figure 3.5).

Figure 3.5: Netscape Navigator's Java console.

The Java console allows the user to see exactly which Java applets are being loaded and executed without having to examine the HTML source directly. This feature can come in handy when you are trying to debug Java and HTML forms.

You just learned that Navigator supports JavaScript 1.1, which is a scripting language that allows you to embed scripted programs directly into HTML code. JavaScript was initially introduced by Netscape in an earlier version of Navigator as a feature known as LiveScript. Because Java applets generally do not interact with other elements on HTML pages, JavaScript is useful in providing a means to tie these types of elements together. Although much of the syntax is similar to Java, there are some major differences. Most notably, JavaScript does not allow you to define new types of objects. Additionally, inheritance is not allowed and JavaScript code is not compiled. Instead, it is embedded within the <SCRIPT> and </SCRIPT> tags in an HTML form. Nevertheless, JavaScript is still a very viable alternative for people who want to add a little interactivity to their Web pages without becoming Java experts.

Security

The approach Navigator 3.0 takes in handling applet security is what separates its Java support from the HotJava browser. HotJava allows the user to set security options, but Navigator does not. With Navigator, Java applets are not allowed to read or write to the local file system under any circumstances; applets are restricted to communicating only with the computer from which they came. In addition, unlike users of HotJava, users of Navigator can turn off Java applet support altogether. This feature was provided primarily to pacify users who were concerned over security problems with early versions of Java. Figure 3.6 shows Navigator's Java options.

Figure 3.6: Netscape Navigator's Preferences dialog box.

Microsoft Internet Explorer 3.0

Although late to the game, Microsoft's latest version of the Web browser, Internet Explorer 3.0, is actually full of features-not the least of which is its support for Java and other interactive technologies. Even though Netscape beat Microsoft to the punch with Java support in earlier versions of Netscape Navigator, Microsoft has managed to make up ground fast and even to throw in a few related extras. Internet Explorer 3.0 includes full support for Java applets and JavaScript, including a just-in-time Java compiler. However, Internet Explorer doesn't support the latest version of JavaScript (version 1.1). Figure 3.7 shows Internet Explorer 3.0 in action. You can download Internet Explorer 3.0 from Microsoft's Web site, which is located at http://www.microsoft.com.

Figure 3.7: Microsoft Internet Explorer 3.0.

Perhaps more exciting than Internet Explorer's direct Java support is the inclusion of Microsoft's own ActiveX technology. ActiveX is a powerful new technology built on Microsoft's popular OLE component technology. ActiveX allows Web developers to embed prebuilt software components, called controls, directly in Web pages, much like Java applets are embedded. Also included in ActiveX is a scripting language called VBScript, which is a scaled-down version of the popular Visual Basic programming language. Both ActiveX controls and VBScript programs can be integrated with Java applets, resulting in an interesting mix of new technologies. For more information about the specifics regarding Java and ActiveX, refer to Chapter 38, "Integrating Java and ActiveX."

Java Support

Similar to Netscape Navigator, Internet Explorer supports Java, JavaScript, and a just-in-time Java compiler. Unlike Navigator, Internet Explorer currently supports only version 1.0 of JavaScript (it does not support the newer version 1.1). Also unlike Navigator, Internet Explorer allows you to disable the just-in-time Java compiler. This is done through the Advanced tab of the Options dialog box, shown in Figure 3.8.

Figure 3.8: Microsoft Internet Explorer's Advanced Options dialog box.

In the Advanced Options dialog box, you may also notice that you can enable or disable Java logging, which is a feature that tracks all Java program activity. In a way, this feature is much like the Java console in Navigator, except that it writes information to a file rather than presenting it in a window.

Security

Internet Explorer, like Navigator, takes a hard line when it comes to Java security. As is true in Navigator, Java applets executing in Internet Explorer are not allowed to read or write to the local file system and are restricted to communicating only with the host computer from which they came. Internet Explorer also provides a means to completely disable Java applets. You set this option using the Security tab in the Options dialog box, shown in Figure 3.9.

Figure 3.9: Microsoft Internet Explorer's Security Options dialog box.

In the Security Options dialog box, you may also notice that Internet Explorer allows you to disable ActiveX controls and plug-ins, as well as ActiveX scripts, which includes both JavaScript and VBScript.

Summary

Because Java applets are only as useful as the Web browsers that support them, this chapter introduced you to the latest Java-enabled browsers. Even though Java is still very young, Web browsers have already come a long way in their internal support for Java. And with the competition heating up over which browser will rule the Web, we can only expect better and faster Java support from all these browsers in subsequent versions.

Each browser you learned about in this chapter took a different approach in how it positioned Java next to its other features. HotJava, which is itself entirely written in Java, is the browser most closely wedded to Java. Netscape Navigator, which was the only commercial browser to adopt Java early on, is probably second to HotJava in its support for Java because it includes the latest release of JavaScript. Internet Explorer, although not as firmly linked to the Java camp, includes a very competitive implementation of Java, JavaScript, and a just-in-time Java compiler. Couple this support with ActiveX and VBScript, and Internet Explorer ultimately provides the most options for Web developers.

Now that you have an idea of what's out there in regard to Java browsers, you're probably eager to find out what's available in terms of Java programming tools. Chapter 4 explores the Java Developers Kit, which is JavaSoft's set of tools for Java development.