Here you can find the source of getLocalHostname()
public static String getLocalHostname()
//package com.java2s; import java.net.*; public class Main { private static String localHostName_ = null; public static String getLocalHostname() { if (localHostName_ == null) try { localHostName_ = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { }/*from w w w . j av a2s . co m*/ return localHostName_; } }