Using Internet Addresses

Internet addresses, also known as IP addresses, are fundamental to Internet communication. You encapsulate IP addresses in InetAddress objects using Java's InetAddress class. That is, each InetAddress object encapsulates the IP address of a particular host computer. The InetAddress class is part of the java.net package.

The InetAddress class is unusual in that it doesn't provide public constructors. You create InetAddress objects by using one of three InetAddress class methods: getByName(), getAllByName(), and getLocalHost().

You will probably find yourself using the InetAddress class's getByName() method most of the time. The getByName() method is declared as follows:

 public static InetAddress getByName(String host) ...

Get JavaBeans Unleashed 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.