URL getDefaultPort Example

URL class getDefaultPort example. This example shows you how to use getDefaultPort method.


URL class getDefaultPort example. public int getDefaultPort() Gets the default port number of the protocol associated with this URL. If the URL scheme or the URLStreamHandler for the URL do not define a default port number, then -1 is returned.

Here is the code
/*
 * @ # GetDefaultPort.java
 * A class repersenting use to GetDefaultPort method 
 * of URL class in java.net package
 * version 23 June 2008
 * author Rose India 
 */

import java.net.*;

public class GetDefaultPort {

    public static void main(String args[]) throws Exception {

        URL url = new URL("http://google.com");

        System.out.println("Default Port " + url.getDefaultPort());
    }
}

Output
Default Port 80

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US