Here you can find the source of getLocalHostName()
public static String getLocalHostName()
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static String getLocalHostName() { return getLocalHost().getHostName(); }// ww w. jav a 2 s . c o m public static InetAddress getLocalHost() { try { return InetAddress.getLocalHost(); } catch (final UnknownHostException e) { throw new IllegalStateException("Unable to obtain local host name"); } } }