0% found this document useful (0 votes)
18 views4 pages

Aamras in Summer

notes

Uploaded by

jagtaptanay80
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)
18 views4 pages

Aamras in Summer

notes

Uploaded by

jagtaptanay80
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/ 4

1.

Develop a program using InetAddress class to retrieve IP address of


computer when hostname is entered by the user.

import java.io.*;
import java.net.*;

public class InetDemoExample {


public static void main(String[] args) {
try {
InetAddress ip = InetAddress.getByName("www.gmail.com");
System.out.println("Host Name: " + ip.getHostName());
System.out.println("IP Address: " + ip.getHostAddress());
} catch (Exception e) {
System.out.println(e);
}
}
}
Output :
2. Write a program using URL class to retrieve the host, protocol,port and
file of URL http:/www.msbte.org.in

import java.net.URL;
import java.net.MalformedURLException;
public class URLRetrive
{
public static void main(String[] args) throws MalformedURLException {
URL url = new URL("https://msbte.org.in/");
System.out.println("Authority: "+ url.getAuthority());
System.out.println("Default Port: "+ url.getDefaultPort());
System.out.println("File: "+ url.getFile());
System.out.println("Path: "+ url.getPath());
System.out.println("Protocol: "+ url.getProtocol());
System.out.println("Reference: "+ url.getRef());
}}
Output :
3. ) Write a program using URL and URLConnection class to retrieve the
date, content type, content length information of any entered URL

import java.net.URL;
import java.net.URLConnection;
import java.io.IOException;
import java.util.Date;

public class URLInfo {


public static void main(String[] args) {
try {
String ad = "https://www.example.com";
URL url = new URL(ad);
URLConnection uc = url.openConnection();
System.out.println("Host Name: Misal_Paav");
System.out.println("Date: " + new Date(uc.getDate()));
System.out.println("Content Type: " + uc.getContentType());
System.out.println("Content Length: " + uc.getContentLength());

} catch (IOException e) {
System.out.println("An error occurred: " + e.getMessage());
}
}
}
Output :

You might also like