About the Examples

Most methods and classes described in this book are illustrated with at least one complete working program, simple though it may be. In my experience, a complete working program is essential to showing the proper use of a method. Without a program, it is too easy to drop into jargon or to gloss over points about which the author may be unclear in his own mind. The Java API documentation itself often suffers from excessively terse descriptions of the method calls. In this book, I have tried to err on the side of providing too much explication rather than too little. If a point is obvious to you, feel free to skip over it. You do not need to type in and run every example in this book, but if a particular method does give you trouble, you are guaranteed to have at least one working example.

Each chapter includes at least one (and often several) more complex program that demonstrates the classes and methods of that chapter in a more realistic setting. These often rely on Java features not discussed in this book. Indeed, in many of the programs, the networking components are only a small fraction of the source code and often the least difficult parts. Nonetheless, none of these programs could be written as easily in languages that didn’t give networking the central position it occupies in Java. The apparent simplicity of the networked sections of the code reflects the extent to which networking has been made a core feature of Java and not any triviality of the program itself. All example programs presented in this book are available online, often with corrections and additions. You can download the source code from http://metalab.unc.edu/javafaq/books/jnp2e and http://www.oreilly.com/catalog/javanp2/.

This book assumes you are using Sun’s Java Development Kit. I have tested all the examples on Windows and many on Solaris and the Macintosh. Almost all the examples given here should work on other platforms and with other compilers and virtual machines that support Java 1.2 (and many on Java 1.1). The few that require Java 1.3 are clearly noted. In reality, every implementation of Java that I have tested has had nontrivial bugs in networking, so actual performance is not guaranteed. I have tried to note any places where a method behaves other than as advertised by Sun.

Get Java Network Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.