A quick example of how to get the name of the localhost using the Java InetAddress class.
String hostname = null;
try {
InetAddress localhost = Address.getLocalHost();
if (localhost != null) {
hostname = localhost.getHostName();
}
} catch (UnknownHostException e) {
e.printStackTrace();
}
System.out.println("Hostname is " + (hostname != null ? hostname : "Unknown") );

