Chapter 5. Networking
Sun Microsystems has long used the slogan “The Network Is
The Computer.” It’s no surprise, therefore, that they designed Java to
be a network-centric language. The java.net
package provides powerful and
easy-to-use networking capabilities. The examples in this chapter
demonstrate those capabilities at a number of different levels of
abstraction. They show you how to:
Use the
URL
class to parse URLs and download the network resources specified by a URLUse the
URLConnection
class to gain more control over the downloading of network resourcesWrite client programs that use the
Socket
class to communicate over the networkUse the
Socket
andServerSocket
classes to write serversSend and receive low-overhead datagram packets
Java 1.4 introduced the New I/O API of java.nio
and its subpackages. This new API is
channel-based instead of stream-based, and can be used for local file
I/O as well as network I/O. java.nio
is particularly suited to high-performance servers, and does not make
the java.net
package obsolete. The
New I/O API is covered in Chapter
6.
Get Java Examples in a Nutshell, 3rd 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.