Friday, December 26, 2008

Details about installing java on different Operating Systems

Sun Microsystems has provided a very nice page providing all the details about steps and links for How to Install Java and also provided  links of different JDK’s for various operating systems.

 Here is the Link : http://www.java.com/en/download/manual.jsp

How do i verify whether an URL is active or not through Java

There are different ways in java through which we can verify whether any specific URL is active or not.
Here is the Java Program which displays success message if the URL is active and Failed message if URL is not active/dead.

URLVerification 
----------------
import java.net.*;
import java.io.*;

public class URLVerification {
    public static void main(String[] args) throws Exception {
        URL url_to_verify = new URL("http://www.google.com");
        try
        {
          URLConnection connObj = url_to_verify.openConnection();
          connObj .connect();
          InputStream stream_to_recieve_data = connObj .getInputStream();
          stream_to_recieve_data.close();  
          System.out.println("Successful in establishing connection.");
        }
        catch (Exception e)
        {
          System.out.println("Failed in establishing connection.");
        }
    }
}
-------------------
I also want to share the few scenarios where we can use this such as:

1. You have to write a code which will call a specific URL to get data after each interval
2. Before Sending request , you can write a filter to verify whether the url is active or not.
3. Directly you want to call a servlet/jsp through a java program to get the status 

I hope my above comments will help you to come up with new ideas as well.

Please provide comments if any...