Java Local Host Get getLocalHostName()

Here you can find the source of getLocalHostName()

Description

Get local host name.

License

Open Source License

Return

the local host name.

Declaration

public static String getLocalHostName() 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *
 * Copyright (c) 2002, 2008 IBM Corporation, Beacon Information Technology Inc. and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  w  w  w  . j  a  v  a  2  s .c  o m
 *   IBM      - Initial API and implementation
 *   BeaconIT - Initial API and implementation
 *******************************************************************************/

import java.net.InetAddress;

public class Main {
    /**
     * Get local host name.
     * @return the local host name.
     */
    public static String getLocalHostName() {
        String sLocalHostName;

        try {
            // Get local host name
            sLocalHostName = InetAddress.getLocalHost().getHostName();
        } catch (Exception e) {
            // Set default local host name
            sLocalHostName = "127.0.0.1";
        }

        // Return local host name
        return sLocalHostName;
    }
}

Related

  1. getLocalhostAddress()
  2. getLocalHostID()
  3. getLocalHostLANAddress()
  4. getLocalHostName()
  5. getLocalHostName()
  6. getLocalHostName()
  7. getLocalHostName()
  8. getLocalHostName()
  9. getLocalHostName()