All About Class InetAddress in Java

0
33
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

InetAddress
InetAddress 

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);//determines the IP address of a host
//,given the host name
public static InetAddress getByAddresses(byte[] addr);//returns an InetAddress object
//given the raw IP Address
public static InetAddress getByAddresses(String host,byte[] addr);//returns an InetAddress object
//based on the provided host name and IP address.
public String getHostName();//returns the host name for this IP address
public static InetAddress getLocalHost();//returns the local host
public String getHostAddress();//returns the IP address String in textual presentation.
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-[email protected] 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.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

LEAVE A REPLY

Please enter your comment!
Please enter your name here