Javatpoint Logo
Javatpoint Logo

Java URL class getDefaultPort() Method

The getDefaultPort() method of URL class is used to get the default port number of the protocol associated with given URL. If the URL scheme or the URLStreamHandler for the URL does not define a default port number, then -1 is returned.

Syntax

Returns

the port number

Since

1.4

Example 1

Output:

Enter Url 
https://www.javatpoint.com/java-date
The Defaultport of the given url is : 443

Example 2

Test it Now

Output:

Given URL is : https://www.google.com/
Default Port 443
Protocal https
Host www.google.com
Next TopicJava URL Class





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA