Javatpoint Logo
Javatpoint Logo

Java InetAddress getByName() method

The getByName() method of InetAddress class determines the IP address of a host from the given host's name.

If the host name is null, then an InetAddress representing an address of the loopback interface is returned.

Syntax:

Parameters:

host - the specified host, or null.

Returns

The getByName() method returns an IP address for the given host name.

Throws

UnknownHostException: if no IP address for the host could be found, or if a scope_id was specified for a global IPv6 address.

SecurityException: if a security manager exists and its checkConnect method doesn?t allow the operation.

Example 1

Test it Now

Output:

46.21.29.40

Example 2

Test it Now

Output:

localhost/127.0.0.1

Next TopicInetAddress Class





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA