Online Java Compiler By
JavaTpoint.com
import java.net.*; public class UrlgetDefaultPortExample2{ URL url; String host,protocol; int port; public void HttpCallerInfo(URL url) { this.url= url; host = url.getHost(); int p = url.getPort(); if (p == -1) { port = url.getDefaultPort(); } else { port = p; } protocol = url.getProtocol(); System.out.println(" Default Port "+port); System.out.println(" Protocal "+protocol); System.out.println(" Host "+host); } public static void main(String args[]) throws Exception { UrlgetDefaultPortExample2 ga=new UrlgetDefaultPortExample2(); URL url=new URL("https://www.google.com"); System.out.println("Given URL is : "+url); ga.HttpCallerInfo(url); } }
Output