package org.kodejava.network;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class HostNameExample {
public static void main(String[] args) {
try {
InetAddress address = InetAddress.getLocalHost();
System.out.println("Hostname: " + address.getHostName());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
An example of output produce by the code snippet above is:
Hostname: Krakatau
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024