Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


getResponse autofunnels

Liquid Web Cloud VPS Hosting

11,407 questions

15,557 answers

573 users

How to use URL in Java

2 Answers

0 votes
import java.net.*; 

public class MyClass {
    public static void main(String args[]) {
        try {
            URL url = new URL("https://www.collectivesolver.com/" + 
                              "26291/how-to-set-decimal-precision-in-c"); 

            System.out.println(url.toString()); 
    
            System.out.println("Protocol = " + url.getProtocol()); 
      
            System.out.println("Host = " + url.getHost()); 
      
            System.out.println("Default port = " + url.getDefaultPort()); 
      
            System.out.println("Query = " + url.getQuery()); 
      
            System.out.println("Path = " + url.getPath()); 
      
            System.out.println("File = " + url.getFile()); 
      
            System.out.println("Reference = " + url.getRef()); 
        }
        catch(MalformedURLException ex) {
             System.out.println(ex);
        }
    }
}



/*
run:

https://www.collectivesolver.com/26291/how-to-set-decimal-precision-in-c
Protocol = https
Host = www.collectivesolver.com
Default port = 443
Query = null
Path = /26291/how-to-set-decimal-precision-in-c
File = /26291/how-to-set-decimal-precision-in-c
Reference = null

*/

 




answered Oct 4 by avibootz
0 votes
import java.net.*; 

public class MyClass {
    public static void main(String args[]) {
        try {
            URL url = new URL("https://www.google.com/search?client=firefox-b-d&q=java+url");

            System.out.println(url.toString()); 
    
            System.out.println("Protocol = " + url.getProtocol()); 
      
            System.out.println("Host = " + url.getHost()); 
      
            System.out.println("Default port = " + url.getDefaultPort()); 
      
            System.out.println("Query = " + url.getQuery()); 
      
            System.out.println("Path = " + url.getPath()); 
      
            System.out.println("File = " + url.getFile()); 
      
            System.out.println("Reference = " + url.getRef()); 
        }
        catch(MalformedURLException ex) {
             System.out.println(ex);
        }
    }
}



/*
run:

https://www.google.com/search?client=firefox-b-d&q=java+url
Protocol = https
Host = www.google.com
Default port = 443
Query = client=firefox-b-d&q=java+url
Path = /search
File = /search?client=firefox-b-d&q=java+url
Reference = null

*/

 




answered Oct 4 by avibootz
...