Preface

Java™’s growth over the last five years has been nothing short of phenomenal. Given Java’s rapid rise to prominence and the general interest in networking, it’s a little surprising that network programming in Java is still so mysterious to so many. This doesn’t have to be. In fact, writing network programs in Java is quite simple, as this book will show. Readers with previous experience in network programming in a Unix, Windows, or Macintosh environment should be pleasantly surprised at how much easier it is to write equivalent programs in Java. That’s because the Java core API includes well-designed interfaces to most network features. Indeed, there is very little application layer network software you can write in C or C++ that you can’t write more easily in Java. Java Network Programming endeavors to show you how to take advantage of Java’s network class library to quickly and easily write programs that accomplish many common networking tasks. These include:

  • Browsing pages on the Web

  • Parsing and rendering HTML

  • Sending email with SMTP

  • Receiving email with POP and IMAP

  • Writing multithreaded servers

  • Installing new protocol and content handlers into browsers

  • Encrypting communications for confidentiality, authentication, and guaranteed message integrity

  • Designing GUI clients for network services

  • Posting data to CGI programs

  • Looking up hosts using DNS

  • Downloading files with anonymous FTP

  • Connecting sockets for low-level network communication

  • Distributing applications across multiple systems with Remote Method Invocation

Java is the first language to provide such a powerful cross-platform network library that handles all these diverse tasks. Java Network Programming exposes the power and sophistication of this library. This book’s goal is to enable you to start using Java as a platform for serious network programming. To do so, this book provides a general background in network fundamentals as well as detailed discussions of Java’s facilities for writing network programs. You’ll learn how to write Java applets and applications that share data across the Internet for games, collaboration, software updates, file transfer and more. You’ll also get a behind-the-scenes look at HTTP, CGI, TCP/IP, and the other protocols that support the Internet and the Web. When you finish this book, you’ll have the knowledge and the tools to create the next generation of software that takes full advantage of the Internet.

About the Second Edition

In the first chapter of the first edition of this book, I wrote extensively about the sort of dynamic, distributed network applications I thought Java would make possible. One of the most exciting parts of writing this second edition was seeing that virtually all of the applications I had postulated have indeed come to pass. Programmers are using Java to query database servers, monitor web pages, control telescopes, manage multiplayer games, and more, all by using Java’s ability to access the Internet. Java in general, and network programming in Java in particular, has moved well beyond the hype stage and into the realm of real, working applications. Not all network software is written in Java yet, but it’s not for a lack of trying. Efforts are well under way to subvert the existing infrastructure of C-based network clients and servers with pure Java replacements. It’s unlikely that Java will replace C for all network programming in the near future. However, the mere fact that many people are willing to use web browsers, web servers, and more written in Java shows just how far we’ve come since 1996.

This book has come a long way too. The second edition has been rewritten almost from scratch. There are five completely new chapters, some of which reflect new APIs and abilities of Java introduced since the first edition was published (Chapter 8, Chapter 12, and Chapter 19 ), and some of which reflect my greater experience in teaching this material and noticing exactly where students’ trouble spots are (Chapter 4, and Chapter 5). In addition, one chapter on the Java Servlet API has been removed, since the topic really deserves a book of its own; and indeed Jason Hunter has written that book, Java Servlet Programming (O’Reilly & Associates, Inc., 1998).

However, much more important than the added and deleted chapters are the changes inside the chapters that we kept. The most obvious change to the first edition is that all of the examples have been rewritten with the Java 1.1 I/O API. The deprecation messages that tormented readers who compiled the first edition’s examples using Java 1.1 or later are now a thing of the past. Less obviously, but far more importantly, all the examples have been rewritten from the ground up to use clean, object-oriented design that follows Java’s naming conventions and design principles. Like almost everyone (Sun not excepted), I was still struggling to figure out a lot of the details of just what one did with Java and how one did it when I wrote the first edition in 1996. The old examples got the network code correct, but in most other respects they now look embarrassingly amateurish. I’ve learned a lot about both Java and object-oriented programming since then, and I think my increased experience shows in this edition. For just one example, I no longer use standalone applets where a simple frame-based application would suffice. I hope that the new examples will serve as models not just of how to write network programs, but also of how to write Java code in general.

And of course the text has been cleaned up too. In fact, I took as long to write this second, revised edition as I did to write the original edition. As previously mentioned, there are 5 completely new chapters, but the 14 revised chapters have been extensively rewritten and expanded to bring them up-to-date with new developments, as well as to make them clearer and more engaging. This edition is, to put it frankly, a much better written book than the first edition, even leaving aside all the changes to the examples. I hope you’ll find this edition an even stronger, longer lived, more accurate, and more enjoyable tutorial and reference to network programming in Java than the first edition.

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.