Create relative url in java

Create relative url in java

package com.w3spoint;
 
import java.net.MalformedURLException;
import java.net.URL;
 
public class URLTest {
  public static void main(String args[]){
	try {
		URL baseURL = new URL("https://www.w3spoint.com");
	        URL relativeURL = new URL(baseURL,"/object-oriented-design-principles-in-java-examples/");
                System.out.println(relativeURL.toString());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
  }
}

Output

https://www.w3spoint.com/object-oriented-design-principles-in-java-examples/
Please Share