I am afraid that you cannot use.
Looking at the Java 8 source code, I see the following code used by the Socket class to check for a valid port in several functions:
private static int checkPort(int port) { if (port < 0 || port > 0xFFFF) throw new IllegalArgumentException("port out of range:" + port); return port; }
This can be found in java.net.InetSocketAddress.checkPort(int)
As you can see, Java itself does not use a named constant.
The code search causes the following hit in java.net.HostPortrange :
static final int PORT_MIN = 0; static final int PORT_MAX = (1 << 16) -1;
But, as you can see, this is not a public link. Another private link appears in java.net.SocketPermission .
So, after checking the above, I came to the conclusion that there is no Java API.
Thirler
source share