Here you can find the source of getHostName()
public static String getHostName()
//package com.java2s; //License from project: LGPL import java.net.*; public class Main { public static String getHostName() { String result = null;// www .j ava 2 s . c o m InetAddress inetAddress = null; try { inetAddress = InetAddress.getLocalHost(); result = inetAddress.getHostName(); } catch (Exception ex) { result = "localhost"; } return result; } }