Here you can find the source of getHostname()
Determines the current host's fully qualified hostname.
public static String getHostname()
//package com.java2s; //License from project: LGPL import java.net.InetAddress; import java.net.UnknownHostException; public class Main { /**// w ww. jav a 2 s .co m * <p>Determines the current host's fully qualified hostname.</p> * @return The fully qualified hostname. */ public static String getHostname() { try { InetAddress ia = InetAddress.getLocalHost(); return ia.getHostName(); } catch (UnknownHostException e) { return null; } } /** * <p>Determines the current host's fully qualified hostname.</p> * @return The fully qualified hostname. */ public static String getHostName() { return getHostname(); } }