Here we are going to look at the approach of identifying the available and active ports used as a server.
1. Create an object of Socket class.
2. Assign a value to i up to which you want to look for the available ports.
3. Pass this integer and hostname to the object of socket class.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.