java tutorial - Java InetAddress class - java programming - learn java - java basics - java for beginners
Learn Java - Java tutorial - Java inetaddress - Java examples - Java programs
- Java InetAddress class represents an IP address.
- The java.net.InetAddress class provides methods to get the IP of any host name for example www.wikitechy.com, www.google.com, www.facebook.com etc.
Methods of InetAddress class
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. |
Sample Code
- The example is given below,