Here you can find the source of getHostname()
public static String getHostname()
//package com.java2s; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.*; public class Main { /**//from ww w . j ava 2 s . c o m * Get the system's Fully Qualified Domain Name as a string * @return the system's FQDN */ public static String getHostname() { String hostname = ""; try { hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException u) { StringTokenizer st = new StringTokenizer(u.getMessage()); while (st.hasMoreTokens()) hostname = st.nextToken(); } return hostname; } }