To get hostName,hostAddress and localHost of current machine

To find hostName,hostAddress and localHost of current system. we get IP address from getLocalHost method.hostName is a computer name.

				
					import java.net.InetAddress;
import java.net.UnknownHostException;

public class MyHostAddress {
	@SuppressWarnings("static-access")
	public static void main(String[] args) throws UnknownHostException {
		InetAddress inetAdd = InetAddress.getLocalHost();
		System.out.println("hostName : " + inetAdd.getHostName() + " hostAddress : " + inetAdd.getAddress()
				+ " localHost : " + inetAdd.getLocalHost());
	}
}
				
			

Output :-
hostName:welcome-PC hostAddress:[B @7852e922 localHost:welcome-PC/192.168.0.100