InetAddress class
The inetaddress class is used to encapsulate the digital IP address and the domain name of the address we discussed earlier.
You have an IP hostname that works with this class, and the IP hostname is simpler and easier to understand than its IP address.
The address number is hidden inside the InetAddress class.
Factory methods in the InetAddress class
The InetAddress class has no obvious constructors. to generate a InetAddress object, you must apply a factory method that is available.
Factory Methods (Factory method ) only a static method in a class returns a convention for that class instance.
For InetAddress, three methods: Getlocalhost (), Getbyname (), and Getallbyname () can be used to create instances of inetaddress.
Getlocalhost () returns only the InetAddress object that symbolizes the local host.
Native address is also localhost,127.0.0.1, these three addresses are one thing.
The Getbyname () method returns a inetaddress that is passed to its hostname.
If these methods cannot resolve host names, they throw a unknownhostexception exception.
On the Internet, it is common to use a name to represent multiple machines.
The Getallbyname () factory method returns an array of inetaddresses classes representing all addresses that are decomposed by a special name.
When a name cannot be broken down into at least one address, it throws a Unknownhostexception exception.
Program examples
Java Network Programming (iv) InetAddress class