How can i check whether a package like javax.servlet.* exists or not in my installation of java?
If you look in the API docs for the installation you have, it will tell you all the installed packages, eg: http://java.sun.com/j2se/1.5.0/docs/api/
In code, you can do something like this:
Package foo = Package.getPackage("javax.servlet");
if(null != foo){
foo.toString();
}else{
System.out.println("Doesn't Exist");
}