Java Local Host Get getLocalHostName()

Here you can find the source of getLocalHostName()

Description

Gets the host name of this local machine

License

Apache License

Return

this local host name

Declaration

public static String getLocalHostName() 

Method Source Code

//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;
    }
}

Related

  1. getLocalHostName()
  2. getLocalHostName()
  3. getLocalHostName()
  4. getLocalHostname()
  5. getLocalHostName()
  6. getLocalHostName()
  7. getLocalHostName()
  8. getLocalhostName()
  9. getLocalHostName()