Here you can find the source of getLocalHostName()
public static String getLocalHostName() throws UnknownHostException
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static String getLocalHostName() throws UnknownHostException { try {/* w w w. j a va 2 s . c om*/ return (InetAddress.getLocalHost()).getHostAddress(); } catch (UnknownHostException uhe) { String host = uhe.getMessage(); if (host != null) { int colon = host.indexOf(':'); if (colon > 0) { return host.substring(0, colon); } } throw uhe; } } public static String getHostAddress() throws UnknownHostException { try { return (InetAddress.getLocalHost()).getHostAddress(); } catch (UnknownHostException uhe) { String host = uhe.getMessage(); if (host != null) { int colon = host.indexOf(':'); if (colon > 0) { return host.substring(0, colon); } } throw uhe; } } }