Java Host Name Get getHostname()

Here you can find the source of getHostname()

Description

Determines the current host's fully qualified hostname.

License

LGPL

Return

The fully qualified hostname.

Declaration


public static String getHostname() 

Method Source Code


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

Related

  1. getHostname()
  2. getHostName()
  3. getHostName()
  4. getHostName()
  5. getHostName()
  6. getHostName()
  7. getHostName()
  8. getHostname()
  9. getHostName()