URL Class

URL Class : Java Networking

About URL Class

URL class is inbuilt java.net package class, using of this class we can find protocol, host name, port number, file name and path of URL. URL is Universal Resource Locator.

Example : 

Website URL : http://www.isssearch.in:80/index.php 

Protocol : http

Host Name : www.isssearch.in

Port : 80

Program on URL [java.net.* package]

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

class url2
{

public static void main(String args[]) throws IOException
{

try
{

URL obj = new URL(“http://www.isssearch.in:80/index.php”); 

System.out.println(“Protocol : ” + obj.getProtocol());
System.out.println(“Host : ” + obj.getHost());
System.out.println(“File : ” + obj.getFile());
System.out.println(“Port : ” + obj.getPort());
System.out.println(“Path : ” + obj.getPath());
System.out.println(“External : ” + obj.toExternalForm());

}
catch(Exception ex)
{

System.out.println(ex);

}

}

}

Output : 

Protocol : http

Host : www.isssearch.in

File : index.php

Port : 80

Path : /index.php

External : http://www.isssearch.in:80/index.php


Download Program 


Best Java Language Books

837total visits,5visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Comments are closed.