In this Tutorials section we cover and explain Factory Method in details for freshers and experienced
previous | Home | Next |
Factory Method For InetAddress Class
getLocalHost()Returns an InetAddres object that represents the IP address of the Current Machine.
public static InetAddress getLocalHost(); throws UnknownHostException; InetAddress a= InetAddress.getLocalHost();
Returns an InetAddress object that representing IP address of a given host.
public static InetAddress getByName(String hostName); throws UnknownHostException;
Returns an array of netAddress object each element of array represent IP addresss of given host.
public static InetAddress[]getAllByName(String hostName); throws UnknownHostException;
Knows Factory Methods of InetAddress Class.
getHostAddress()Returns IP address as a String.
public string getHostAddress();
Returns Host Name.
public string getHostName();
//To find out IP Addresss of a Machine on the Network.
//Machine Name is receive as Command Line Argument.
import java.net.*; class IPFinder { public static void main(String arr[]) { try { InetAddress a=InetAddress.getbyName(arr[0]); System.out.println("IP Adress is"+ a.getByName()); } catch (Exception e) { System.out.println(e); } } }
previous | Home | Next |