static bool portIsFree(int port) { try { new ServerSocket(port).close(); true; } catch (IOException e) { false; } }