InetAddress: getHostName() : InetAddress « java.net « Java by API






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.");
    }

  }

}

   
    
  








Related examples in the same category

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