how to create url object in java?

URL is an acronym for Uniform Resource Locator. It refers to a resource on the World Wide Web.

URL example:

https://www.w3spoint.com

The java.net.URL class is used to represent an URL.

Create url object in java

package com.w3spoint;
 
import java.net.MalformedURLException;
import java.net.URL;
 
public class URLTest {
  public static void main(String args[]){
	try {
            String myUrl = "https://www.w3spoint.com";
            URL url = new URL(myUrl);
            System.out.println(url.toString());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
  }
}

Output

https://www.w3spoint.com
Please Share