Here you can find the source of getLocalHost()
public static InetAddress getLocalHost()
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static InetAddress getLocalHost() { try {/* w w w . j a v a 2 s . co m*/ return InetAddress.getLocalHost(); } catch (UnknownHostException e) { return getLocalHostByName(); } } public static InetAddress getLocalHostByName() { try { return InetAddress.getByName("localhost"); } catch (UnknownHostException e) { throw new RuntimeException("Exception getting InetAddress for localhost.", e); } } }