Name

Package java.net

Synopsis

The java.net package provides a powerful and flexible infrastructure for networking. This introduction describes the most commonly used classes in brief. Note that as of Java 1.4, the New I/O API of java.nio and java.nio.channels can be used for high-performance nonblocking networking. See also the javax.net.ssl package for classes for secure networking using SSL.

The URL class represents an Internet uniform resource locator (URL). It provides a very simple interface to networking: the object referred to by the URL can be downloaded with a single call, or streams may be opened to read from or write to the object. At a slightly more complex level, a URLConnection object can be obtained from a given URL object. The URLConnection class provides additional methods that allow you to work with URLs in more sophisticated ways. Java 1.4 introduced the URI class; it provides a powerful API for manipulating URI and URL strings but does not have any networking capabilities itself. Java 5.0 defines APIs for defining and registering cache, cookie, and proxy handlers to be used by built-in protocol handlers when network resources are requested through the URL class. See RequestCache, CookieHandler, ProxySelector, and Proxy.

If you want to do more than simply download an object referenced by a URL, you can do your own networking with the Socket class. This class allows you to connect to a specified port on a specified Internet host and read and write data using the ...

Get Java in a Nutshell, 5th 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.