Skip to main content.

Web Based Programming Tutorials

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

Java Unleashed

Java Unleashed--ch06.htm Previous Page toc Index Next Page

Chapter 6

Java distributes content

Because Java is designed for distributing executable content, all Java applets, except those on the user’s local host, are distributed across networks. However, Java’s power as a language for expressing executable content involves more than the distribution of applets. Java also makes the following possible:

This chapter examines these capabilities in detail, showing examples and key Java statements that make these features possible. Later parts of this book will guide you through more details of Java programming. In particular, the package is covered in Chapter 28, and protocol and content handlers are covered in Chapters 30 and 31.

The Significance of Network Distribution and Retrieval

Chapter 4 showed an applet (Magic) that allowed you to draw on images (refer to Figure 4.6). The network relationships involved in this simple applet are fairly significant. Figure 6.1 shows the connections among the content distribution, network retrieval, and display involved in this applet.

The figure shows the network retrieval taking place:

This network interaction involves three Web servers and the user’s computer, besides the routers involved with the Internet network connections that relay the information from two continents. This intermingling of content demonstrates the integration Java can help accomplish. As a Web client, a Java-enabled browser is already an information integrator for many protocols. Combined with capabilities to distribute and retrieve content, Java adds another dimension to information retrieval and integration.

Figure FIGURE 6.1.

Summary of information transfer in Magic applet demonstration.

Handling New Protocols and Formats

The most significant feature of a Java-enabled browser is that it is not fixed. Instead of relying on a built-in set of code for handling information delivery protocols and a fixed set of helper applications to handle media formats, a Java-enabled browser is set up so that it can adjust to learn new protocols and media formats.

This capability significantly changes the Web:

Retrieving and Sharing Network Information

The protocol and content handlers can expand what a Java-enabled browser can interpret and display, opening the Web for delivery of diverse information. Java also has the capability to enrich how browsers retrieve information, giving Java programmers the chance to make applets to retrieve network information.


Patrick Chan, writing about his Surf-o-matic demonstration program at, calls it “almost as good as watching TV!” Surf-o-matic is a Web tour guide that can “take over” a user’s browser and change the pages. This type of tour has great potential for advertising, education, and other applications.

Surf-o-matic is a Java applet that uses a set of classes to implement the Surf-o-matic Control Panel (see Figure 6.2). This control panel enables you to cruise the Web based on some lists of “random” URLs. First, you select which list or lists of URLs you want to surf. Then click on the Go button on the panel, and Surf-o-matic takes over your browser. Surf-o-matic switches the page every 20 seconds (or a time interval you can set) to a new page from the random lists you’ve chosen. For example, Yahoo’s ( random list of Web pages is very large and is used in the example in Figure 6.2.

Figure FIGURE 6.2.

Surf-o-matic in action.

Figure 6.2 shows Surf-o-matic as it is retrieving a new page. Even in its present form, it is a useful standalone application. One use is as a kiosk application to demonstrate the content of the Web.

Surf-o-matic is based on Matthew Gray’s Web Autopilot, which uses the Netscape browser’s client-pull feature. However, a HotJava browser can use Java code to implement this same type of task; it then does not have to revert to a client-pull technique. Patrick Chan’s demonstration in Surf-o-matic is a quick example showing this flexibility of Java for network information retrieval.


JavaScript (described in detail in part IX of this book) is another programming language that you can use in conjunction with Java to distribute executable content over the Web. JavaScript is different from Java. Rather than interpreting Java bytecodes in a separate file, JavaScript is written into an HTML document and is interpreted by a Netscape Web browser.

Many companies have endorsed JavaScript as an open standard for scripting. Using JavaScript, a programmer can detect and act upon many user navigation actions, such as button-clicking, mouse position, and so on. Figure 6.3 shows an example of JavaScript in action. This simple calculator operates using HTML forms elements. However, its processing isn’t accomplished using Common Gateway Interface (CGI) programming. Instead, a JavaScript program gives the user the answer to the calculation. This shift changes the site of computation from the information provider’s server to the user’s client and host.

Figure FIGURE 6.3.

JavaScript in action.

A Java Graffiti Board

Dan Guinan developed a Java Graffiti Chalkboard that demonstrates sharing information using a Java applet. This applet is located at

Through the applet, the user can manipulate tools such as chalk and an eraser to draw on the board; the resulting drawing is shared among users. Figure 6.4 shows a sample board.

Developer Dan Guinan explains that the Java Grafitti Chalkboard applet relies on a socket- based server to load and save chalkboard data. This server resides on the same machine as the Web server and communicates with the Java applet directly. The result is a “networked” applet that not only provides animation and interaction with the user but network communication as well.

Figure FIGURE 6.4.

The Java Graffitti Board.


Java not only changes what can happen on a Web page, it also changes what can be retrieved and displayed on a Web page. Special handlers for new protocols and content extend what a Java-enabled browser can find and interpret. Java enables network information retrieval within applets, making it possible for an applet to “take over” a user’s display and exhibit a series of network resources or provide a way for users to share information across a network.

Previous Page toc Index Next Page