For more detail about response status codes see RFC 2616 section 10. Calling connect() is by the way not needed if you’re determining the response data. It will implicitly connect.

/**
* Pings a HTTP URL. This effectively sends a HEAD request and returns true if the response code is in
* the 200-399 range.
* @param url The HTTP URL to be pinged.
* @param timeout The timeout in millis for both the connection timeout and the response read timeout. Note that
* the total timeout is effectively two times the given timeout.
* @return true if the given HTTP URL has returned response code 200-399 on a HEAD request within the
* given timeout, otherwise false.
*/
public static boolean ping(String url, int timeout) {
url = url.replaceFirst("https", "http"); // Otherwise an exception may be thrown on invalid SSL certificates.