Java URL class getDefaultPort() Method24 Mar 2025 | 1 min read 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 |
Java Method The getContent() Method of URL gets the contents of this URL. This method is a shorthand for openConnection().getContent(). Syntax public final Object getContent() throws IOException Returns The contents of this URL. Throw IOException - if an I/O exception occurs. Example 1 import java.net.URL; import java.util.Scanner; public class UrlGetContentExample1{ public static void main(String args[])throws...
1 min read
Java Method The toString() method of URL class constructs a string representation of this URL. The string is created by calling the toExternalFile() method of the stream protocol handler for this object. Syntax public String toString() Overrides toString in class Object Returns A string representation of this object. Example 1 import java.net.*; public class...
1 min read
Java Method The equals() method of URL class compares this URL for equality with another URL object. It returns false if the given object is not a URL. If IP address of two different is same, then it considered equivalent host. Syntax public boolean equals(Object obj) Overrides equals in...
1 min read
Java method The getAuthority() method of the URL class is used to get the authority part of given URL. Syntax public String getAuthority() Returns The authority part of this URL Since 1.3 Example 1 import java.net.URL; import java.util.Scanner; public class UrlgetAuthorityExample1 { public static void main(String args[]) throws Exception { //passing url in constructor Scanner s= new Scanner(System.in); System.out.println("Enter Url...
1 min read
Java Method The openConnection() method of URL class opens the connection to specified URL and URLConnection instance that represents a connection to the remote object referred by the URL. It should be noted that a URLConnection instance does not establish the actual network connection on the...
3 min read
Java method The toURI() method returns URI equivalent to given URL. This method functions in the same way as new URI (this.toString()). Syntax public URI toURI() throws URISyntaxException Returns A URI instance is equivalent to this URL. Throw URISyntaxException - if this URL is not formatted strictly according to RFC2396 and...
2 min read
Java Method The getProtocol() Method of URL class returns the protocol name of this URL. Syntax public String getProtocol() Returns The protocol of this URL. Example 1 import java.net.URL; import java.util.Scanner; public class UrlgetProtocolExample1 { public static void main(String args[])throws Exception { //passing url in constructor URL url1=new URL("https://www.tpointtech.com/URL-class"); System.out.println("Url: "+url1); // Getting protocal used in given url System.out.println("Protocol...
1 min read
Java Method The getFile() method of URL class returns the file name of the URL. The returned file portion will be the same as getPath(), plus the concatenation of the value of getQuery() if any. Syntax public String getFile() Parameter NA Returns the file name of this URL, or an empty...
1 min read
Java Method The getRef() method of URL class returns the anchor(reference) of the URL or the null if not exist . Syntax public String getRef() Returns The anchor (also known as the "reference") of this URL, or null if one does not exist Example 1 import java.io.*; import java.net.*; class URLGetRefExample1 { public static...
1 min read
Java Method The getPort() method of URL class returns the port number of the Specified URL. Syntax public int getPort() Returns The port number, or -1 if the port is not set Example 1 import java.net.URL; import java.util.Scanner; public class UrlgetPortExample1 { public static void main(String args[])throws Exception { //passing url in URL class constructor URL url1=new...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India