Java URL class getDefaultPort() MethodLast Updated : 17 Mar 2025 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. SyntaxReturnsthe port number Since1.4 Example 1Output: Enter Url https://www.tpointtech.com/java-date The Defaultport of the given url is : 443 Example 2Output: Given URL is : https://www.google.com/ Default Port 443 Protocal https Host www.google.com Next TopicJava URL Class |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India