Java tutorial
//package com.java2s; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static boolean isInternetWorking() { boolean success = false; try { URL url = new URL("https://google.com"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(8000); connection.connect(); success = connection.getResponseCode() == 200; } catch (IOException e) { e.printStackTrace(); } return success; } }