InetSocketAddress getHostName Example
InetSocketAddress class getHostName example. This example shows you how to use getHostName method.
InetSocketAddress class getHostName example. public final String getHostName() Gets the hostname.
Here is the code
/*
* @ # GetHostName.java
* A class repersenting use to GetHostName method
* of InetSocketAddress class in java.net package
* version 23 June 2008
* author Rose India
*/
import java.net.*;
public class GetHostName {
public static void main(String[] args) throws Exception {
//Get local host.
InetAddress inetAddress = InetAddress.getLocalHost();
InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, 1313);
//Gets InetAddress.
System.out.println("Hostname "+inetSocketAddress.getHostName());
}
} |
|