Here you can find the source of getLocalHostName()
public static String getLocalHostName()
//package com.java2s; /* Licensed under the Apache License, Version 2.0 (the "License"); you may */ import java.net.InetAddress; import java.net.UnknownHostException; public class Main { private static String localHostName; /**//ww w . ja v a 2 s .c o m * Gets the host name of this local machine * @return this local host name */ public static String getLocalHostName() { if (localHostName == null) { try { InetAddress addr = InetAddress.getLocalHost(); localHostName = addr.getHostName(); } catch (UnknownHostException e) { } } return localHostName; } }