We can get the System name for a Windows or Linux machine using the getHostName() method of the InetAddress class of java.net package after getting the IP address of the system using getLocalHost() method of the same class. The class InetAddress gets the IP address of any hostname. getLocalHost() method of the InetAddress class gets the address of the local host. getHostName() gets the hostname for a given IP address or returns the textual representation of the IP address if the operation is not allowed by the security manager.
public String getHostName()
Returns: The address of the host for a given IP address or the textual representation of the IP address if the operation is not allowed.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.