// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.*;
import java.net.*;

public class URLTest {
   public static void test1(String strurl) {
      try {
         URL url = new URL(strurl);
         Object obj = url.getContent();
         System.out.println(strurl + " : ja");
      } catch (IOException ex) {
         System.out.println(strurl + " : nej");
      }
   }
   public static void test2(String strurl) {
      try {
         URL url = new URL(strurl);
         HttpURLConnection con = (HttpURLConnection) url.openConnection();
         con.connect();
         if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
            System.out.println(strurl + " : ja");
         } else {
            System.out.println(strurl + " : nej");
         }
         con.disconnect();
      } catch (MalformedURLException e) {
         System.out.println(strurl + " : nej");
      } catch (FileNotFoundException e) {
         System.out.println(strurl + " : nej");
      } catch (IOException e) {
         System.out.println(strurl + " : nej");
      }
   }
   public static void test(String strurl) {
      test1(strurl);
      test2(strurl);
   }
   public static void main(String[] args) {
      test("http://www.eksperten.dk/");
      test("http://www.eksperten.dk/notexist.html");
      test("http://www.notexist.dk/");
      test("http://www.vajhoej.dk/");
      test("http://www.vajhoej.dk/notexist.html");
      test("http://www.dell.dk/");
   }
}
