Here you can find the source of getShortHostname()
public static String getShortHostname()
//package com.java2s; //License from project: Apache License import java.net.InetAddress; public class Main { /**/*ww w.jav a 2 s. co m*/ * @return Hostname of this machine (without the fulld domain info) */ public static String getShortHostname() { return getFullHostname().replaceAll("\\..*", ""); } /** * @return Full hostname of this machine. */ public static String getFullHostname() { // find the hostname String hostname = "unknown"; try { final InetAddress host = InetAddress.getLocalHost(); hostname = host.getHostName(); } catch (Exception ignore) { // SWALLOWED } return hostname; } }