Here you can find the source of getHostname()
public static String getHostname()
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.UnknownHostException; public class Main { /**//from w w w.j a va 2 s .c o m * @return Hostname of this computer, e.g. {@code hostname.domain.tld} */ public static String getHostname() { String hostName; final InetAddress localHost; try { localHost = InetAddress.getLocalHost(); hostName = localHost.getHostName(); } catch (UnknownHostException ignore) { hostName = "localhost"; } return hostName; } }