i did it.look at the code below:
---------------------------------
import java.net.*;
public class getHostname{
public static void main(String[] args)throws UnknownHostException{
InetAddress address=InetAddress.getLocalHost();
System.out.println(address); //print host IP
String hostname=address.getHostName(); //get host name
System.out.println(hostname); //print host name
}
}