img
DatagramSocket
NetworkInter face
URLClassLoader
DatagramSocketImpl
PasswordAuthentication
URLConnection
HttpCookie (Added by
Proxy
URLDecoder
Java SE 6.)
HttpURLConnection
ProxySelector
URLEncoder
IDN (Added by Java SE 6.) ResponseCache
URLStreamHandler
Inet4Address
SecureCacheResponse
The java.net package's interfaces are listed here:
ContentHandlerFactor y
DatagramSocketImplFactor y SocketOptions
CookiePolicy (Added by Java SE 6.)
FileNameMap
URLStreamHandlerFactor y
CookieStore (Added by Java SE 6.)
SocketImplFactor y
In the sections that follow, we will examine the main networking classes and show
several examples that apply to them. Once you understand these core networking classes,
you will be able to easily explore the others on your own.
InetAddress
The InetAddress class is used to encapsulate both the numerical IP address and the domain
name for that address. You interact with this class by using the name of an IP host, which is
more convenient and understandable than its IP address. The InetAddress class hides the
number inside. InetAddress can handle both IPv4 and IPv6 addresses.
Factor y Methods
The InetAddress class has no visible constructors. To create an InetAddress object, you
have to use one of the available factory methods. Factory methods are merely a convention
whereby static methods in a class return an instance of that class. This is done in lieu of
overloading a constructor with various parameter lists when having unique method names
makes the results much clearer. Three commonly used InetAddress factory methods are
shown here:
static InetAddress getLocalHost( )
throws UnknownHostException
static InetAddress getByName(String hostName)
throws UnknownHostException
static InetAddress[ ] getAllByName(String hostName)
throws UnknownHostException
The getLocalHost( ) method simply returns the InetAddress object that represents the local
host. The getByName( ) method returns an InetAddress for a host name passed to it. If these
methods are unable to resolve the host name, they throw an UnknownHostException.
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home