WRITE A PROGRAM IN JAVA TO GET THE HOST Name

Host Name exist in Java InetAddress class, create an instance of this class and then get the Host Name with method getHostName. This method is mostly used when we deal with networking in Java.

Source Code

package com.lepnetworking.com;
import java.net.InetAddress;
import java.net.UnknownHostException;


public class Net_working {

    public static void main(String[] args) throws UnknownHostException {
        InetAddress Hname = InetAddress.getLocalHost();
    System.out.println( "Your Host Name is : "+Hname.getHostName());
    }
    
}

OutPut of the Program

Java Programming

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment