0% found this document useful (0 votes)
60 views3 pages

Practical No 14

ajp practical 14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views3 pages

Practical No 14

ajp practical 14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical No 14

Write a program to demonstrate the use of InetAddress class and its


factory methods

import java.io.*;
import java.net.*;
public class InetDemo
{
public static void main(String[] args)
{
try
{
InetAddress ip=InetAddress.getByName("localhost");
System.out.println("Host Name: "+ip.getHostName());
System.out.println("IP Address: "+ip.getHostAddress());
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output :
Write a program using factory method

import java.net.*;
class FactoryMethodsDemo
{
public static void main(String ar[]) throws UnknownHostException
{
InetAddress addr1 = InetAddress.getLocalHost();
System.out.println(addr1);
InetAddress addr2 = InetAddress.getByName("msbte.org.in");
System.out.println(addr2);
InetAddress addr3[ ] = InetAddress.getAllByName("www.google.com");
for (int i=0; i<addr3.length; i++)
System.out.println(addr3[i]);
}
}

Output :

You might also like