GeeCON Prague 2014*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Interface problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Interface problem." Watch "Interface problem." New topic
Author

Interface problem.

CoffeeFan
Greenhorn

Joined: Oct 11, 2002
Posts: 12
Hi,
Since methods can not be defined but be declared in an interface. Am I right? Why can we invoke the method of interface HttpServletRequest directly without causing any error(like what is usually done in doPost() function)? Where are the implementation of those methods?
Many thanks.


SCJP
Paul McKenna
Ugly Redneck
Ranch Hand

Joined: Jul 08, 2000
Posts: 1006
Hi,
The signature of the method is

But what is actually passed into the method are objects that implements the respective interfaces. Each server may implement the two objects in different ways, but for a developer to understand all you need is a reference to the top level interface.
SR


Commentary From the Sidelines of history
Sam Dalton
Author
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
Originally posted by CoffeeFan:
Hi,
Since methods can not be defined but be declared in an interface. Am I right? Why can we invoke the method of interface HttpServletRequest directly without causing any error(like what is usually done in doPost() function)? Where are the implementation of those methods?
Many thanks.

Hey there.
The reason that this works is that the object passed to doPost etc is a concreate implementation fo the interface provided by the vendor of your webcontainer.
So when you call a method on the HttpServletRequest interface, you are really callign a methhod on the underlying concrete implementation.
Hope this clears things up for you.
Cheers
Sam


<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
Bill Wang
Ranch Hand

Joined: Jun 28, 2001
Posts: 31
One point I want to add is that the concrete implementation class for HttpServletRequest is provided by the servlet engine automatically and transparent to the developer.


SCJP<br />SCWCD<br />SCEA Part I
CoffeeFan
Greenhorn

Joined: Oct 11, 2002
Posts: 12
Hi, all.
Thank you very much for your explanations. I got it.
 
GeeCON Prague 2014
 
subject: Interface problem.