All About Class InetAddress in Java




InetAddress  class represents an internet protocol (IP) address.Application should use the methods written below:

  • getLocalHost()
  • getByName()
  • getAllByName()
to create a new InetAddress instance.
The structure of class InetAddress  is given as:

public final class java.io.InetAddress extends java.lang.Object{
//methods
public boolean equals(Object obj);
public byte[] getAddress();
public static InetAddress[] getAllByName(String host);
public static InetAddress getByName(String host);
public String getHostName();
public static InetAddress getLocalHost();
public int hashcode();
public String toString();
}
 
How Internet Addressing work in Java
Java looks at the whole internet as a collection of host machine -each host is identified by a number called port number.Internet names rae in the form of user readable String like-somebody@gmail.com instead of raw numbers.Java handles this situation nicely.In java.net package this InetAddress class allows us to specify an address in a high level fashion "host.subdomain.domain".This class then converts this textual name into 32 bits binary String form (like 192.170.54.34).The InetAddress class has no visible constructor. In order to create an InetAddress object,we have to use one of the factory methods.Factory methods are static methods that return an instance of the class they reside in.
All About Class InetAddress in Java All About Class InetAddress in Java Reviewed by Animesh Chatterjee on October 12, 2018 Rating: 5

No comments:

Powered by Blogger.