What is Inet address

?– Every computer connected to a network has an IP address. An IP address is a number that uniquely identifies each computer on the Net. An IP address is a 32-bit number.

In Java, InetAddress is a class that represents an Internet Protocol (IP) address. It is part of the java.net package and provides methods for working with IP addresses. The InetAddress class can be used to create instances representing both IPv4 and IPv6 addresses.

Here’s a brief overview of some key aspects of the InetAddress class:

  1. Creating Instances:
    • You can create an InetAddress instance by using static factory methods like getByName() or getLocalHost().
    • Example:
      java
      InetAddress address = InetAddress.getByName("www.example.com");
  2. Getting Information:
    • The class provides methods to retrieve information about the IP address, such as its host name (getHostName()), its IP address in byte array form (getAddress()), and its textual representation (toString()).
    • Example:
      java
      String hostName = address.getHostName();
      byte[] ipAddress = address.getAddress();
      String ipAddressString = address.toString();
  3. Utility Methods:
    • InetAddress also includes methods like isReachable() to check if the address is reachable, and getCanonicalHostName() to get the fully qualified domain name.
    • Example:
      java
      boolean reachable = address.isReachable(1000); // Check if the address is reachable within 1 second.
      String canonicalHostName = address.getCanonicalHostName();

In summary, InetAddress is a Java class used to represent and work with IP addresses, providing methods for creating instances, retrieving information, and performing utility operations related to network addressing.