InetAddress: getHostName()


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

public class MainClass {

  public static void main(String[] args) {

    try {
      InetAddress address = InetAddress.getLocalHost();
      System.out.println("My name is " + address.getHostName());
    } catch (UnknownHostException e) {
      System.out.println("I'm sorry. I don't know my own name.");
    }

  }

}
Home 
  Java Book 
    Networking  

InetAddress:
  1. InetAddress
  2. InetAddress: getAllByName(String name)
  3. InetAddress: getByName(String host)
  4. InetAddress: getCanonicalHostName()
  5. InetAddress: getHostAddress()
  6. InetAddress: getHostName()
  7. InetAddress: getLocalHost()
  8. InetAddress: isReachable(int timeout)