Java.net.Inet4Address class in Java Last Updated : 24 Mar, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report This class extends the InetAddress class and represents an IPv4 address. It provides methods to interpret and display useful information about IP addresses. Methods of this class take input in 4 formats: d.d.d.d: When this format is used as input, each of the given values are assigned to 4 bytes of the IP address from left to right.d.d.d: When this format is used as input, the last part is interpreted as a 16-bit number and assigned to the rightmost 2 bytes as the host address. This is generally used for specifying a class-B address.d.d: When this format is used as input, the last part is interpreted as a 24-bit number and assigned to the rightmost 3 bytes as the host address. This is generally used for specifying a class-A address.d: When this format is used as input, the given value is directly stored as a network address without any rearrangement.Methods : MethodsDescriptionequals(Object obj)This method compares this object against the specified object.getAddress()This method returns the raw IP address of this InetAddress object.getHostAddress()This method returns the IP address string in the textual presentation form.hashCode()This method returns a hashcode for this IP address.isAnyLocalAddress()This method utility routine check if the InetAddress is a wildcard address.isLinkLocalAddress()This method utility routine check if the InetAddress is a link-local address.isLoopbackAddress()This method utility routine check if the InetAddress is a loopback address.isMCGlobal()This method utility routine check if the multicast address has a global scope.isMCLinkLocal()This method utility routine check if the multicast address has a link scope.isMCNodeLocal()This method utility routine check if the multicast address has node scope.isMCOrgLocal()This method utility routine to check if the multicast address has organization scope.isMCSiteLocal()This method utility routine check if the multicast address has site scope.isMulticastAddress()This method utility routine check if the InetAddress is an IP multicast address.isSiteLocalAddress()This method utility routine check if the InetAddress is a site-local address.Java Implementation : Java // Java program to illustrate various // Inet4Address class methods import java.net.Inet4Address; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; public class inet4add { public static void main(String args[]) throws UnknownHostException { String url = "www.geeksforgeeks.org"; Inet4Address ip1 = (Inet4Address) Inet4Address.getByName(url); Inet4Address ip2 = (Inet4Address) InetAddress.getByName("www.yahoo.com"); // Following methods checks the property of the thus created object. // getAddress() method System.out.println("Address : " + Arrays.toString(ip1.getAddress())); // getHostAddress() method System.out.println("Host Address : " + ip1.getHostAddress()); // isAnyLocalAddress() method System.out.println("isAnyLocalAddress : " + ip1.isAnyLocalAddress()); // isLinkLocalAddress() method System.out.println("isLinkLocalAddress : " + ip1.isLinkLocalAddress()); // isLoopbackAddress() method System.out.println("isLoopbackAddress : " + ip1.isLoopbackAddress()); // isMCGlobal() method System.out.println("isMCGlobal : " + ip1.isMCGlobal()); // isMCLinkLocal() method System.out.println("isMCLinkLocal : " + ip1.isMCLinkLocal()); // isMCNodeLocal() method System.out.println("isMCNodeLocal : " + ip1.isMCNodeLocal()); // isMCOrgLocal() method System.out.println("isMCOrgLocal : " + ip1.isMCOrgLocal()); // isMCSiteLocal() method System.out.println("isMCSiteLocal : " + ip1.isMCSiteLocal()); // isMulticastAddress() method System.out.println("isMulticastAddress : " + ip1.isMulticastAddress()); // isSiteLocalAddress() method System.out.println("isSiteLocalAddress : " + ip1.isSiteLocalAddress()); // hashCode() method System.out.println("hashCode : " + ip1.hashCode()); // equals() method System.out.println("ip1==ip2 : " + ip1.equals(ip2)); } } Output : Address : [52, 84, 102, -116] Host Address : 52.84.102.140 isAnyLocalAddress : false isLinkLocalAddress : false isLoopbackAddress : false isMCGlobal : false isMCLinkLocal : false isMCNodeLocal : false isMCOrgLocal : false isMCSiteLocal : false isMulticastAddress : false isSiteLocalAddress : false hashCode : 877946508 ip1==ip2 : false Comment More infoAdvertise with us Next Article Java.net.Inet4Address class in Java R rishabh Mahrsee 1 Improve Article Tags : Advance Java Similar Reads Java.net.Inet6Address class in Java This class represents IPv6 address and extends the InetAddress class. Methods of this class provide facility to represent and interpret IPv6 addresses. Methods of this class takes input in the following formats: x:x:x:x:x:x:x:x -This is the general form of IPv6 address where each x can be replaced w 5 min read Java.net.InetSocketAddress class in Java This class implements IP socket address( combination of IP address and port number). The objects of this class are immutable and can be used for binding, connecting purposes. Constructors : 1. InetSocketAddress(InetAddress addr, int port) : This constructor is similar to the general structure of a s 4 min read Java.net.NetworkInterface class in Java This class represents network interface, both software as well as hardware, its name, list of IP addresses assigned to it, and all related information. It can be used in cases when we want to specifically use a particular interface for transmitting our packet on a system with multiple NICs. What is 6 min read java.net.InetAddress Class in Java public class InetAddress extends Object implements Serializable: The java.net.InetAddress class provides methods to get the IP address of any hostname. An IP address is represented by 32-bit or 128-bit unsigned number. InetAddress can handle both IPv4 and IPv6 addresses. There are 2 types of address 6 min read Java.net.InterfaceAddress class in Java This class represents a network interface address. Every device that has an IP address has an IP address on the network interface. In fact the ping command doesn't ping a device but the devices interface address. Java provides certain methods to deal with interface addresses which can be used in pla 2 min read Like