Java network programming books: A comparative review

Laurence sifts through another batch of Java books, trying to separate the nuggets from fool's gold

Five Java network programming titles landed on my doorstep for this review:

  • Java Network Programming, by Elliotte Rusty Harold (O'Reilly)

  • Java Network Programming, by Merlin and Conrad Hughes, Michael Shoffner, and Maria Winslow (Manning, an imprint of Prentice-Hall)

  • Advanced Java Networking, by Prashant Sridharan (Prentice-Hall)

  • Java Networking and Communications, by Todd Courtois (Prentice-Hall)

  • Java Networking and AWT API SuperBible, by Nataraj Nagaratnam, Brian Maso, and Arvind Srinivasan (Waite)

Before I review the books in detail, let's quickly look at each book's main attributes:

Table 1: Java network programming books overview
Java Network Programming (O'Reilly)Java Network Programming (Manning)Advanced Java NetworkingJava Networking and CommunicationsJava Networking and AWT API SuperBible
Price4.954.959.959.959.99
Pages, Chapters (Appendices)422, 15 (0)519, 29 (4)366, 12 (2)317, 8 (1)930, 13 (6)
IndexVery GoodPoorVery PoorPoorVery Good
GlossaryNoNoVery PoorNoGood
CD-ROMNo (but source on FTP site)YesYesYesYes
Authors14113

Object-

Orientation

AverageVery GoodAverageAverageAverage
TCP/IPAveragePoorPoorPoorPoor
MultithreadingPoorVery GoodAverageAverageGood
StreamsPoorVery GoodAverageAveragePoor
SerializationAverageAveragePoorVery PoorNone
RMIVery GoodAverageVery GoodNoneNone
ServletsGoodNoneGoodNoneNone

The last few attributes require some explanation:

The Object-Orientation attribute indicates to what extent the author(s) of the respective book used Java the way it is meant to be used: in an object-oriented way. Good Java books, whatever their focus, enforce good object-oriented practices. Inferior books use Java as if it were C or Pascal; that is, in a procedural way. Networking applications are very good candidate applications that benefit from being designed and implemented using object-orientation, so a good Java network programming book requires a strong emphasis on object-oriented analysis, design, and programming (OOA, OOD, and OOP).

The TCP/IP attribute indicates to what extent the book gives you a thorough TCP/IP primer. Personally, I would expect such a primer in any Java networking book; yet none of the books in this review dwell much on the internals of TCP/IP. But don't let this particular oversight worry you; the whole point of Internet programming using Java is that the API lifts you to such heights of abstraction that much of the IP, UDP, and TCP protocol details disappear. If you're like me, and you still want to know how the Internet works "under the hood," then you should invest in the classic (and excellent) TCP/IP bible TCP/IP Illustrated, Volume 1 - The Protocols by W. Richard Stevens (Addison-Wesley).

The Multithreading attribute indicates to what extent the book uses and/or explains multithreading. Multithreading is a key ingredient in any non-trivial networking applications (especially for server-side programs).

The Streams attribute indicates to what extent the book uses and/or explains Java's java.io classes. Making heavy use of stream classes in networking applications can simplify a design and make it more flexible.

The Serialization attribute indicates to what extent the book covers the 1.1 Serialization API and its uses. Pre 1.1 books do not touch on this API at all.

The RMI attribute indicates to what extent the book covers the 1.1 Remote Method Invocation API and its uses. Pre 1.1 books do not discuss RMI at all.

Finally, the Servlets attribute indicates to what extent the book covers servlets (server applets). Pre 1.1 books do not cover servlets at all.

Java Network Programming (O'Reilly)

Java Network Programming

treats the core java.net, java.rmi, and javax.servlet packages (Java's packages that contain the APIs most relevant to network programming) in a thorough and logical manner. Chapter 1 sets out to entice the reader by enumerating some classic, state-of-the-art networking applications (chat, collaborative, and shopping cart applications, for example) for which Java can be easily used.

Java Network Programming

Chapters 2 and 3 introduce the basic TCP/IP and WWW concepts and mechanisms. The remaining 13 chapters use the various Java networking APIs as a guiding thread. Most of these chapters discuss a few classes at a time, consistently discussing constructors, methods, and exceptions, in that order. These chapters then end with a helpful section called "Some Useful Programs." Within this section, you'll find such programs as Javalookup, which performs DNS lookups from the command line; Pagesaver, which grabs a single Web page and saves it to your local hard disk while transforming all relative URLs to absolute URLs; and ImageSizer, which grabs a single Web page containing images and saves it while regenerating the image tags to contain width and height information. (Pages that omit this information do not allow the browser to display the page before all images are loaded, so ImageSizer magically fixes this annoying problem.)

The order of the chapters is logical, commencing with a discussion of the InetAddress, URL, Socket, ServerSocket, DatagramPacket, and DatagramSocket classes. The more advanced material continues with a discussion of the URLConnection class and the non-trivial URL protocol and content handlers system, MulticastSocket, RMI, and the Java Server API. The API material provided in each chapter is enhanced by adding extra layers of abstraction. For example, Chapter 9, which deals with UDP programming, presents a class (UDPClient) that hides the low-level details of byte arrays normally required for UDP-level programming.

Despite the overall quality of the book, there are still several problems that manage to harm it. At a global level, Harold almost totally ignores multithreaded programming. This is very surprising since few non-trivial networking applications can be written in a single-threaded fashion. The book is also very sparse on figures and diagrams. The quality of code identifiers also leaves much to be desired; many of them are just one or two characters in length (a, e, o, u, s, r, p1, p2), or ignore established case conventions (uppercase variables, lowercase constants, lowercase class names). Using just two spaces as indentation unit, deeply nesting try-catch statements, and catching Exception instead of more specific exception types further erodes code quality in this otherwise above-average book.

Java Network Programming (Manning)

This

Java Network Programming

is very different from its identically named competitor. This book devotes a lot of chapters to cryptographic theory and implementation, and the bulk of the material bypasses much of the microscopic detail of Java's networking classes to build interesting and well-designed networking application frameworks on top of them. In addition, the book spends a surprisingly large number of chapters discussing Java's I/O stream classes (as a prerequisite for designing the frameworks later on). The debatably large amount of pages used to study the stream classes is more than offset by the very high quality of Part III, "Real Networking Applications," where stream classes form the architectural heart of a framework for client/server and virtual peer-to-peer applications.

Java Network Programmingming

Following Chapter 1, "Introduction to Networking," the authors clearly show that they consider secure communications a very important topic: Chapters 2 and 3 are called "Introduction to Cryptography" and "The Java Security Model," respectively. And it doesn't end there. Five more chapters (for a total of 7 out of 29) are devoted to increasingly advanced cryptography, encryption protocols, and algorithms. Personally, I disagree that secure communications need to be covered in such detail. Although an important topic in its own right, it should be covered in just one or two chapters in a book with "Network Programming" as its title (admittedly the front cover does state "Covers Cryptographic techniques for secure Internet applications," so readers are forewarned).

The book's main strength is its very high-level approach to designing networking applications. The following quotation is just one small example of which wavelength these authors are on: "...the MessageCopier will be the only thread that can experience an IOException as a result of a failure in the underlying communications channel. We can thus write an application that does not need to be able to handle communications failures occurring wherever a read() call occurs. Instead, we can write most of the code to only handle errors of incorrect message formats and other programmer errors...." This is software engineering in action, not Java hacking, and is why I really liked this book. Many authors can show you how to hack a bit of code, but few can show you how to design clean and flexible systems.

Another aspect of the book that impressed me was the quality and consistency of the diagrams. To explain the architecture of their stream-based networking applications, the authors do not use a conventional notation (like a Booch object diagram or such), but rather their own, infinitely clearer (!), iconography. Some of the later diagrams start to look so much like electronic circuit diagrams that they are almost small pieces of art. I loved them.

The book is not without its share of errors, though. One of the more serious errors is found in Chapter 27, "Object Serialization and Persistence." Twice the authors state that ObjectOutputStream inherits from DataOutputStream. These statements are incorrect since ObjectOutputStream inherits from OutputStream and implements the ObjectOutput interface. ObjectOutput then implements the DataOutput interface. The problem with this error (which at first doesn't look very important) is that the authors further state that ObjectOutputStream.writeInt() is inherited from DataOutputStream.writeInt(), implying that ObjectOutputStream streams are somehow compatible with DataOutputStream streams, which is again false. The streams produced by ObjectOutputStream and DataOutputStream are totally incompatible, which is why JavaSoft couldn't subclass DataOutputStream to produce ObjectOutputStream in the first place!

On the code front, as with the O'Reilly book, the authors use extremely poor program identifiers, including i1, o0, mI, qO (these would undoubtedly be qualified as "horrors" in Steve McConnell's Code Complete, the bible of good coding practice (published by Microsoft Press)). In this case, the choice of identifiers seriously degrades the readability of the programs, even more so than in the case of the O'Reilly book. Surprisingly, in view of the otherwise excellent use of diagrams, the authors also forgot or did not deem it necessary to include class hierarchy diagrams for either Java's networking packages or their own. In the case of Java's networking packages, this omission becomes a problem because the authors also do not provide complete class listings. This means that the reader is left in the dark as to the full extent of the classes and methods available to the programmer.

Advanced Java Networking

If you read September's game programming books review, you'll remember that I am always suspicious of books containing the word "Advanced" in their title. Regrettably,

Advanced Java Networking

arrived this month to confirm my suspicions. The first chapter called "Basic Java" talks about the absolute basics to such an extent that you just know the remainder of the book will not deliver on the promise of its title. This is a shame because the table of contents sounds exciting due to the spectrum of subjects covered: Sockets, IDL, RMI, JDBC, the Java Web Server, and JMAPI, among others. Unfortunately, all of this material is presented in a very disappointing manner. The explanations are often sloppy (or just plain wrong), the author's writing style is sloppy, the program listings are sloppy, and the diagrams are...you guessed it, sloppy.

Advanced Java Networking

Let's begin with the sloppy explanations. Here are a few entries from the glossary:

  • "Encapsulation: Object-oriented programming, practice of."
  • "Language Mapping: The means necessary to take one language and convert its syntax and semantics to another language."
  • "Serialization: The act of transforming a Java object into a string representation."
  • "Thread: A series of executable steps that are executed along with other steps."
  • "UDP: Unreliable Datagram Protocol."

Any Java programmer with some experience will instantly recognize the flaws in the above "definitions." Within the text, the author further mixes up the following concept pairs: byte and character, class and object, and subclassing and implementing an interface.

1 2 Page
Join the discussion
Be the first to comment on this article. Our Commenting Policies
See more