Java Network Programming (iv) InetAddress class

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.