Java Utililty Methods Local Host Get

List of utility methods to do Local Host Get

Description

The list of methods to do Local Host Get are organized into topic(s).

Method

StringgetLocalHostName()
get Local Host Name
final String result = InetAddress.getLocalHost().toString();
final int slashIndex = result.indexOf((int) '/');
if (slashIndex >= 0) {
    return result.substring(0, slashIndex);
return result;
StringgetLocalHostName()
Set the host name variable.
String hostName = "";
try {
    hostName = java.net.InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ex) {
    hostName = System.getenv("COMPUTERNAME"); 
if (hostName == null || hostName.isEmpty()) {
    hostName = System.getenv("COMPUTERNAME"); 
...
StringgetLocalHostName()
Gets the host name for the local machine.
java.net.InetAddress addr = null;
try {
    addr = java.net.InetAddress.getLocalHost();
} catch (Exception ignore) {
    return (null);
return (addr.getHostName());
StringGetLocalHostName()
Get Local Host Name
String localHostName = "Unknown";
try {
    InetAddress lhost = java.net.InetAddress.getLocalHost();
    localHostName = lhost.getHostName();
    if ("localhost".equals(localHostName))
        localHostName = lhost.getHostAddress();
} catch (Exception e) {
    localHostName = "Unknown";
...
StringgetLocalHostName()
get Local Host Name
return getLocalHost().getHostName();
StringgetLocalHostName()
get Local Host Name
try {
    return (InetAddress.getLocalHost()).getHostName();
} catch (UnknownHostException uhe) {
    String host = uhe.getMessage();
    if (host != null) {
        int colon = host.indexOf(':');
        if (colon > 0) {
            return host.substring(0, colon);
...
StringgetLocalHostName()
Retrieves the localhost's hostname, or if unavailable, the ip address
try {
    return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
    NetworkInterface networkInterface = NetworkInterface.getNetworkInterfaces().nextElement();
    if (networkInterface == null)
        throw e;
    InetAddress ipAddress = networkInterface.getInetAddresses().nextElement();
    if (ipAddress == null)
...
StringgetLocalHostname()
Get the local hostname.
try {
    return getLocalHost().getHostName();
} catch (UnknownHostException ignored) {
    return LOCALHOST;
StringgetLocalHostName()
Gets the local host name.
try {
    return InetAddress.getLocalHost().getHostName();
} catch (final UnknownHostException e) {
    System.err.println("Unable to get host name");
    return "";
StringgetLocalHostName()
Gets the host name of this local machine
if (localHostName == null) {
    try {
        InetAddress addr = InetAddress.getLocalHost();
        localHostName = addr.getHostName();
    } catch (UnknownHostException e) {
return localHostName;
...