Taking the port from URL. Port is a 16-bit number to know the services offered by the network server, each service has a port, if you want to access the service shall be connected to the appropriate port, the port has a particular service is called the standard port, eg port 80 http protocol has (80 standard ports), all services have a port number below 1024, whereas port numbers above 1024 are custom port that we use when they want to make a server, so the server should use when making port above 1024
In this article will be given a script that can help you get the port number specified in the URL, to take the first port we create an object of class URL, then created a variable that holds the value of the url given port, then use a method which URL to display port getPort (); Integer port number that is accommodated by a variable of type Integer, then the number is issued to the console, as was done by the script below
--------^^^^^^^^^^^^^^^^^^------------------
package javalearning;
import java.net.*;
public class AmbilPort {
public static void main(String[] args) {
try{
URL url = new URL("http://www.yahoo.com");
Integer protocol = url.getPort();
System.out.println(protokol);
}catch(Exception ue){
}
}
}
---------------------------------------------------
....