Each host name has an IP assigned to it. Sometimes it is useful to have a routine for converting an IP to its hostname. Following routine does exactly that:

Java Code:
String ipAddress = "127.0.0.1";
InetAddress inetAddress = null;

        try {
            inetAddress = InetAddress.getByName(ipAddress);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
System.out.println("InetAddress object has this: " + ipAddress.toString());

System.out.println("Host name :" + inetAddress.getHostName());

System.out.println("canonical host name: " + inetAddress.getCanonicalHostName());