Java URLThe Java URL class represents an URL. URL is an acronym for Uniform Resource Locator. It points to a resource on the World Wide Web. For example: A URL contains many information:
Constructors of Java URL classURL(String spec) Creates an instance of a URL from the String representation. URL(String protocol, String host, int port, String file) Creates an instance of a URL from the given protocol, host, port number, and file. URL(String protocol, String host, int port, String file, URLStreamHandler handler) Creates an instance of a URL from the given protocol, host, port number, file, and handler. URL(String protocol, String host, String file) Creates an instance of a URL from the given protocol name, host name, and file name. URL(URL context, String spec) Creates an instance of a URL by parsing the given spec within a specified context. URL(URL context, String spec, URLStreamHandler handler) Creates an instance of a URL by parsing the given spec with the specified handler within a given context. Commonly used methods of Java URL classThe java.net.URL class provides many methods. The important methods of URL class are given below.
Example of Java URL classTest it NowOutput: Protocol: http Host Name: www.javatpoint.com Port Number: -1 File Name: /java-tutorial Let us see another example URL class in Java. Output: Protocol: https Host Name: www.google.com Port Number: -1 Default Port Number: 443 Query String: q=javatpoint&oq=javatpoint&sourceid=chrome&ie=UTF-8 Path: /search File: /search?q=javatpoint&oq=javatpoint&sourceid=chrome&ie=UTF-8 Next TopicURLConnection class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India