Java hostname example - How do I convert an IP address into a hostname?

Converting a numeric IP address to a hostname with Java is straightforward, just use the InetAddress class. Here's a Java example that demonstrates this:

package com.devdaily.javasamples;

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

/**
 * Shows how to convert an IP address into a hostname.
 * Created by Alvin Alexander, http://devdaily.com.
 */
public class InetAddressExample
{
  public static void main(String[] args) 
  throws UnknownHostException
  {
    String hostname = InetAddress.getByName("192.168.1.1").getHostName();
    System.out.println("hostname = " + hostname);
  }

}