Here you can find the source of getHostname()
public static String getHostname()
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static String getHostname() { try {/*ww w . jav a 2 s . c om*/ String result = InetAddress.getLocalHost().getHostName(); if (result != "") return result; } catch (UnknownHostException e) { } String host = System.getenv("COMPUTERNAME"); if (host != null) return host; host = System.getenv("HOSTNAME"); if (host != null) return host; return "unknown"; } }