0% found this document useful (0 votes)
13 views2 pages

Java Practical15

Uploaded by

Priyanka Thadke
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)
13 views2 pages

Java Practical15

Uploaded by

Priyanka Thadke
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/ 2

Name:- Priyanka Khandu Thadke

Class:-A(CO5I) Roll no:- 60


Practical no:-15 write a program to demostrate the use of URL and URLConnwction class
and its methods.
Program code:-

1.Execute the following code and write the output.

import java.net.*;

class URLDemo

public static void main(String args[]) throws MalformedURLException

{URL hp = new URL("https://www.javatpoint.com/javafx-tutorial");

System.out.println("Protocol: " + hp.getProtocol());

System.out.println("Port: " + hp.getPort());

System.out.println("Host: " + hp.getHost());

System.out.println("File: " + hp.getFile());

System.out.println("Ext:" + hp.toExternalForm());

}}
Output:-
Exercise:-

Q.1) 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;

public class URLInfoRetriever {

public static void main(String[] args) {

try {

URL url = new URL("http://www.msbte.org.in");

System.out.println("Protocol: " + url.getProtocol());

System.out.println("Host: " + url.getHost());

int port = url.getPort();

System.out.println("Port: " + (port == -1 ? "Default (80)" : port));

System.out.println("File: " + url.getFile());

} catch (Exception e) {

System.out.println("An error occurred: " + e.getMessage());

}
}
Output:-

You might also like