its behavior is unpredictable. Web sites can use CGI programs to provide some of
these capabilities, but they're still limited to HTML for the user interface.
Writing Java programs that talk to Internet servers is easy. Java's core library includes
classes for communicating with Internet hosts using the TCP and UDP protocols of
the TCP/IP family. You just tell Java what IP address and port you want, and Java
handles the low-level details. Java does not support NetWare IPX, Windows NetBEUI,
AppleTalk, or other non-IP-based network protocols; but this is rapidly becoming a
nonissue as TCP/IP becomes the lingua franca of networked applications. Slightly
more of an issue is that Java does not provide direct access to the IP layer below TCP
and UDP, so it can't be used to write programs such as ping or traceroute. However,
these are fairly uncommon needs. Java certainly fills well over 90% of most network
programmers' needs.
Once a program has connected to a server, the local program must understand the
protocol that the remote server speaks and properly interpret the data the server sends
back. In almost all cases, packaging data to send to a server and unpacking the data
received is harder than simply making the connection. Java includes classes that help
your programs communicate with certain types of servers, most notably web servers.
It also includes classes to process some kinds of data, such as text, GIF images, and
JPEG images. However, not all servers are web servers, and not all data is text, GIF,
or JPEG. Therefore, Java lets you write protocol handlers to communicate with
different kinds of servers and content handers that understand and display different
kinds of data. A Java-enabled web browser can automatically download and install the
software needed by a web site it visits. Java applets can perform tasks similar to those
performed by Netscape plug-ins. However, applets are more secure and much more
convenient than plug-ins. They don't require user intervention to download or install
the software, and they don't waste memory or disk space when they're not in use.
1.1.2 Repeatedly Retrieve Data
Web browsers retrieve data on demand; the user asks for a page at a URL and the
browser gets it. This model is fine as long as the user needs the information only once,
and the information doesn't change often. However, continuous access to information
that's changing constantly is a problem. There have been a few attempts to solve this
problem with extensions to HTML and HTTP. For example, server push and client
pull are fairly awkward ways of keeping a client up to date. There are even services
that send email to alert you that a page you're interested in has changed.
[3]
[3]
See, for example, the URL-minder at http://www.netmind.com/.
A Java client, however, can repeatedly connect to a server to keep an updated picture
of the data. If the data changes very frequently—for example, a stock price—a Java
application can keep a connection to the server open at all times, and display a
running graph of the stock price on the desktop. Figure 1.5 shows only one of many
such applets. A Java program can even respond in real time to changes in the data: a
stock ticker applet might ring a bell if IBM's stock price goes over $100 so you know
to call your broker and sell. A more complex program could even perform the sale
without human intervention. It is easy to imagine considerably more complicated
combinations of data that a client can monitor, data you'd be unlikely to find on any