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

Practical No. 15: Write A Program To Demonstrate The Use of Url and Urlconnection Class and Its Methods

This document provides instructions for a practical on using the URL and URLConnection classes in Java. Students will write a program to demonstrate using these classes and their methods to access a resource over a network. The URL class represents URLs and allows specifying the protocol, host, port, and file location of a resource. The URLConnection class is used to access attributes of remote resources after establishing a connection via a URL. Students are provided example code to execute that creates a URL object for a website and prints the protocol and port using URL methods.

Uploaded by

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

Practical No. 15: Write A Program To Demonstrate The Use of Url and Urlconnection Class and Its Methods

This document provides instructions for a practical on using the URL and URLConnection classes in Java. Students will write a program to demonstrate using these classes and their methods to access a resource over a network. The URL class represents URLs and allows specifying the protocol, host, port, and file location of a resource. The URLConnection class is used to access attributes of remote resources after establishing a connection via a URL. Students are provided example code to execute that creates a URL object for a website and prints the protocol and port using URL methods.

Uploaded by

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

Advanced Java Programming (22517)

Practical No. 15: Write a program to demonstrate the use of URL


and URLConnection class and its methods

I. Practical Significance:
The Uniform resource locator in java allows the user to access the particular file or
resource which might be stored on any local or remote machine. The URL specifies
the complete path by which user can access file. It contains protocol address, port
number and location of the particular resource.

II. Relevant Program Outcomes (POs)


 Basic knowledge: Apply knowledge of basic mathematics, sciences and basic
engineering to solve the computer group related problems.
 Discipline knowledge: Apply Computer Programming knowledge to solve the
computer group related problems.
 Experiments and practice: Plan to perform experiments and practices to use the
results to solve the computer group related problems.
 Engineering tools: Apply relevant Computer programming / technologies and
tools with an understanding of the limitations.
 Individual and Team work: Function effectively as a leader and team member in
diverse/multidisciplinary teams.
 Communication: Communicate effectively in oral and written form.

III. Competency and Practical skills


To develop a program using URL and URLConnection class
The practical is expected to develop the following skills:
1. Able to identify different types of ports and protocols
2. Able to develop an application using URL and URLConnection class.

IV. Relevant Course Outcome(s)


Develop java programs using networking components

V. Practical Outcome (PrOs)


Write a program to demonstrate the use of URL and URLConnection class and its
methods
VI. Relevant Affective domain related Outcome(s)
1. Follow precautionary measures.
2. Follow naming conventions.
3. Follow ethical practices.

VII. Minimum Theoretical Background


The URL provides easy to understand format to uniquely identify or address
information on the internet. URLs are ample; every browser uses them to identify
information on the Web. URL class provides a simple, concise API to access
information across the Internet using URLs.
URLConnection is a class which is used to access the attributes of remote resource.
Once we made a connection to the remote resource, we are ready to use
URLConnection to check the properties of remote object before actually transporting
it locally.

Maharashtra state Board of Technical Education 80


Advanced Java Programming (22517)

The URL and URLConnection classes are good enough for simple programs that want
to connect to HTTP servers to fetch content.
List of URL Class Methods and Constructors:
1. public URL (String protocol, String host, int port, String file) throws
MalformedURLException
2. public URL (String protocol, String host, String file) throws
MalformedURLException
3. public URL(String url) throws MalformedURLException
4. public URL(URL context, String url) throws MalformedURLException
Methods:
1. public String getPath()
2. public String getAuthority()
3. public String getHost()
4. public String getFile()

List of URLConnection class Methods and Constructors:


The openConnection() method returns a java.net.URLConnection, an abstract class
whose subclasses represent the various types of URL connections.
Methods:
1. Object getContent()
2. String getContentEncoding()
3. int getContentLength()
4. String getContentType()
5. public URL getURL()

VIII. Resources required (Additional)–

Nil

IX. Resources used (Additional)

Sr.
Name of Resource Broad Specification Quantity Remarks (If any)
No.
1

X. Program Code: Teacher must assign a separate program statement to group of


3-4 students.
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());

Maharashtra state Board of Technical Education 81

You might also like