IP Address in Java Program

IP address in java. This is a java program that displays the system’s IP address. An Internet Protocol address is represented by the InetAddress class. To get the IP address string in textual format, we use this class’s getHostAddress() method. Here is the source code for the Java program that displays the system’s IP address.

import java.net.InetAddress;
public class Main
public static void main(String args[]) throws Exception
InetAddress IP = InetAddress.getLocalHost();
System.out.println("IP address= "+IP.getHostAddress());



IP address

IP Address in Computer

An IP address (Internet Protocol address) is a numerical identification assigned to each device connected to a computer network that communicates using the Internet Protocol. An IP address is used for two purposes: identifying a host or network interface, and addressing a specific location.

INET Address in Java

The InetAddress class contains methods for obtaining the IP address of any host name, such as www.noteshippo.com, www.google.com, www.facebook.com, and so on. A 32-bit or 128-bit unsigned number is used to represent an IP address. 

The IP address and its accompanying host name are represented by an instance of InetAddress. The Java InetAddress class’s getLocalHost() function returns an instance of InetAddress with the local host name and address. First, the system’s host name is retrieved, and then that name is resolved into InetAddress.