100% found this document useful (1 vote)
147 views

URL (Uniform Resource Locator) Resource Locator.: - URL Is Also Sometimes Called As Universal

URL stands for Uniform Resource Locator and is used to identify resources on the World Wide Web. A URL contains the protocol, domain name, and file path to uniquely identify a resource. The URL class in Java represents a URL and allows constructing URLs from strings or by specifying the protocol, host, port, and file. It provides methods to retrieve individual components of the URL.

Uploaded by

vijithacvijayan
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
147 views

URL (Uniform Resource Locator) Resource Locator.: - URL Is Also Sometimes Called As Universal

URL stands for Uniform Resource Locator and is used to identify resources on the World Wide Web. A URL contains the protocol, domain name, and file path to uniquely identify a resource. The URL class in Java represents a URL and allows constructing URLs from strings or by specifying the protocol, host, port, and file. It provides methods to retrieve individual components of the URL.

Uploaded by

vijithacvijayan
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

URL(Uniform Resource Locator)

URL is also sometimes called as Universal


resource Locator.

Class URL represents a Uniform Resource Locator,
a pointer to a "resource" on the World Wide Web.

A resource can be something as simple as a file or
a directory, or it can be a reference to a more
complicated object, such as a query to a database
or to a search engine.
For example
http:// www.google.com/index.html
In general, a URL can be broken into several parts.
http(Hypertext Transfer Protocol): is used to
transfer the data between web server and the host
machine.
www( World Wide Web) : is a service that used to
retrieve the information.
.com: It is called as Domain name. Google is the
organization name. .com specifies that it is
commercial organization.



URL
public URL(String protocol,
String host,
int port,
String file) throws MalformedURLException

Creates a URL object from the specified protocol, host, port number, and
file.

Parameters:
protocol - the name of the protocol to use.
host - the name of the host.
port - the port number on the host.
file - the file on the host

Throws:
MalformedURLException - if an unknown protocol is specified.


URL Constructors
URL( fullURL )
URL( "http://www.google.com/index.html" );

URL( baseURL, relativeURL )
URL base = new URL("http://www.google.com/" );
URL class = new URL( base, "/index.html " );

URL( protocol, baseURL, relativeURL )
URL( "http", www.google.com, "/index.html" )

URL( protocol, baseURL, port, relativeURL )
URL( "http", www.google.com, 80,"/index.html" )
URL Methods
getProtocol( )
getHost( )
getPort( )
getFile( )
getContent( )
openStream()
openConnection()
URL Connection Classes
High level description of network service
Access resource named by URL
Can define own protocols
Examples
URLConnection Reads resource
HttpURLConnection Handles web page
JarURLConnection Manipulates Java Archives
URLClassLoader Loads class file into JVM
import java.net.*;
import java.io.*;
class url
{
public static void main(String args[]) throws Exception
{

URL n1 = new URL("http://java.sun.com:80/docs/index");
System.out.println("Protocol:"+n1.getProtocol());
System.out.println("Host :"+n1.getHost());
System.out.println("File Name :"+n1.getFile());
System.out.println("Port :"+n1.getPort());

}
}

You might also like