Sometimes it is required to get the host name and address of the machine on which a Java program is being run. Following example shows how to do that:

Java Code:
InetAddress addr = InetAddress.getLocalHost();
String hostName = addr.getHostName();
String hostAddress = addr.getHostName();