View Single Post
  #2 (permalink)  
Old 04-21-2008, 07:54 AM
sanjeevtarar's Avatar
sanjeevtarar sanjeevtarar is offline
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Quote:
Originally Posted by pooja.gupta84 View Post
1. the service() method of the GenericServlet class accepts 2 parameters...one is of the ServletRequest and the other is of the type ServletResponse. My question is that ServletRequest and ServletResponse are interfaces in the javax.servlet package. How can you create an object of its type? Interfaces cant have objects...only classes can..right?
In This case there is no creation of objects, just creating the reference variable of interface type. In Java we use "new" operator to create objects. ServletRequest request; is only creating reference variable. and it can be done with no problem. You can do it at your own classes.

And one more thing : Why you can not create objects of Interface : Because interfaces are public abstract by default and you can not instantiate an abstract thing in Java. But you can make an Reference variable of abstract thing.

Reference Variable and Making Object are two different thing in Java.

for e.g.

TestClass tc; // Creating Reference Variable that stores the reference only

tc = new TestClass(); // Creating objects.



Quote:
2. can a method return an object of type interface?
A method of the Servlet interface - getServletConfig returns an object of type interface :
ServletConfig getServletConfig()
How is this possible?
It is not returning an object....it is returning an Object reference variable only.

Quote:
3. which other web servers apart from the apache tomcat does servlet support? Can servlets be run on iis, pws or any other server?
JBoss, WEblogic, WebSphear...and many others just do googling.

If any doubt please feel free to ask.


sanjeev
Reply With Quote