Here you can find the source of getLocalHostName()
public static String getLocalHostName()
//package com.java2s; //License from project: Apache License import java.net.InetAddress; public class Main { public static String getLocalHostName() { try {// ww w.j a va 2 s . c o m InetAddress addr = InetAddress.getLocalHost(); return addr.getHostName(); } catch (Exception e) { return ""; } } }