Java URL.getDefaultPort()

Syntax

URL.getDefaultPort() has the following syntax.

public int getDefaultPort()

Example

In the following code shows how to use URL.getDefaultPort() method.


import java.io.IOException;
import java.net.URL;
//from  www.  j  av  a2  s .co  m
public class Main {

  public static void main(String[] args) {
    try {
      URL url = new URL("http://www.java2s.com/query?abc=def");
      System.out.println("URL is " + url.toString());
      System.out.println("authority is " + url.getAuthority());
      System.out.println("default port is " + url.getDefaultPort());
      System.out.println("query is " + url.getQuery());
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.net »




CookieManager
CookiePolicy
CookieStore
DatagramPacket
DatagramSocket
HttpCookie
HttpURLConnection
InetAddress
JarURLConnection
MulticastSocket
ServerSocket
Socket
SocketAddress
URI
URL
URLConnection
URLDecoder
URLEncoder