Structure of the Problem Requirements
In this problem we will learn how to take Host name (PC Name) in Java Program . 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. Here is the Source Code of this problem which help you in better understanding .
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
Host Name |
Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.
0 comments:
Post a Comment