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:// [Link]/[Link]
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( "[Link] );
URL( baseURL, relativeURL )
URL base = new URL("[Link] );
URL class = new URL( base, "/[Link] " );
URL( protocol, baseURL, relativeURL )
URL( "http", [Link], "/[Link]" )
URL( protocol, baseURL, port, relativeURL )
URL( "http", [Link], 80,"/[Link]" )
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 [Link].*;
import [Link].*;
class url
{
public static void main(String args[]) throws Exception
{
URL n1 = new URL("[Link]
[Link]("Protocol:"+[Link]());
[Link]("Host :"+[Link]());
[Link]("File Name :"+[Link]());
[Link]("Port :"+[Link]());
}
}