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 create a string of repeated characters? - September 1, 2023
- How do I convert datetime string with optional part to a date object? - August 28, 2023
- How do I split large excel file into multiple smaller files? - April 15, 2023