logo image

How to get Host name in Java


Hot to get the System name/ Host name/ Machine name in Java?

1 Answer

2 years ago by

String hostName = "UNKNOWN";
try {
	hostName = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
	System.out.println("Unable to resolve host");
}
System.out.println("HostName is:" + hostName);
2 years ago by Megamind