Tuesday, November 25, 2014

Find the hostname of the local machine

import java.net.*;

class myName {

  public static void main (String args[]) {

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

  }

}

1 comment:

Unknown said...

Efficient codes can be updated soon...