Below snippet print the name of system.
public static String getLocalHostName() throws UnknownHostException {
InetAddress localhost = InetAddress.getLocalHost();
return localhost.getHostName();
}
Find the below working application.
LocalHostNameDetails.java
package com.sample.app.net;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class LocalHostNameDetails {
public static String getLocalHostName() throws UnknownHostException {
InetAddress localhost = InetAddress.getLocalHost();
return localhost.getHostName();
}
public static void main(String[] args) throws UnknownHostException {
System.out.println(getLocalHostName());
}
}
No comments:
Post a Comment