code: public static boolean isPortAvailable(String host, int port) {
          try {
              Socket socket = new Socket(host, port);
              socket.close();
              return false;
          } catch (IOException e) {
              return true;
          }
      }
docs: See if a port is available for listening on by trying connect to it
  and seeing if that works or fails
  
  @param host
  @param port
  @return