Skip to content

URL Class

http://abc.com:8080/test.php

Constructors

  1. public URl (String protocol, String host, int port, String file)
  2. public URl (String protocol, String host, String file)
  3. public URl (URL Contex String url)
  4. public URl (String url)

Methods

  1. public String getProtocol()
  2. public String getHost()
  3. public String getPort()
  4. public String getFile()
  5. public String getQuery() // ?name = "GCES"

Implementation

import java.net.*;

class URLDemo {

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

        URL obj = new URL("http://www.thearjun.tech:80/index.htm");
        System.out.println("Protocol : " + obj.getProtocol());
        System.out.println("Hostname : " + obj.getHost());
        System.out.println("Port : " + obj.getPort());
        System.out.println("File Hosted : " + obj.getFile());
        System.out.println("External Form : " + obj.toExternalForm());
    }
}