Feb 292012
How to get the hostname of a local machine using Java
Answer:
The following codes illtsraeted how to get the hostname of the local machine using Java.
import java.net.InetAddress;
public class Test {
public static void main(String[] args) {
try {
InetAddress addr = InetAddress.getLocalHost();
// Get hostname
String hostName = addr.getHostName();
System.out.println(hostName);
} catch (Exception e) {}
}
}