InetAddress Class

Posted By on April 29, 2016

Download PDF
Java URL
Introduction to JDBC

Java InetAddress class represents an IP address.

The class provides methods to get the IP of any host name.

The InetAddress class has no visible constructors.

To create an InetAddress object, you have to use one of the available factory methods.

Method Description
public static InetAddress getByName(String host) throws UnknownHostException it returns the instance of InetAddress containing LocalHost IP and name.
public static InetAddress getLocalHost() throws UnknownHostException it returns the instance of InetAdddress containing local host name and address.
public String getHostName() it returns the host name of the IP address.
public String getHostAddress() it returns the IP address in string format.

Example of Java InetAddress class

public class InetDemo{
public static void main(String[] args){
InetAddress ip=InetAddress.getByName(“”);

System.out.println(“Host Name: “+ip.getHostName());
System.out.println(“IP Address: “+ip.getHostAddress());
}catch(Exception e){System.out.println(e);}


Host Name:
IP Address: x.x.x.x

Java URL
Introduction to JDBC

Download PDF