CodesJava

Easy learning with example program codes

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://codesjava.com

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

Create url object in java

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

Output

https://codesjava.com
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status