• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCWCD - Charles Lyons

 
Aj Deschanel
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading this for SCWCD 1.5. To say the truth, I am not really excited about the book, grammatical errors, and I do not really understand the English language exposed throughout the book, Amazon shows 6 reviews (all 5 stars), I know I should have not bought it, but... the problem is this now, I just read this question as chapter review question:

Which abstract class or interface must be extended or implemented to provide an HTTP servlet ?

A) javax.servlet.Servlet (interface)
B) javax.servlet.GenericServlet (interface)
C) javax.servlet.GenericServlet (abstract class)
D) javax.servlet.http.HttpServlet (abstract class)
E) javax.servlet.http.GenericHttpServlet (abstract class)

I thought the answer should be D only (since HTTP was mentioned in the question), but I was surprised that the correct answer is provided to be A.

Here's the author explanation:

Only Servlet must be ever iimplemented - the other are just convenience classes. The appropriate classes to use are C if you want a protocol independent servlet, or D for an HTTP specific servlet.


what do you guys think ?!
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aj, since the question is about SCWCD, I'm moving it to the SCWCD forum...
 
Aj Deschanel
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:Aj, since the question is about SCWCD, I'm moving it to the SCWCD forum...

Thanks Ankit.
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the question stands to me, I also think that the answer should be D, because the question specifically mentions HTTP servlet.

Edit: On a second thought, if we implement Servlet interface to create a servlet, we can serve HTTP requests. The words "provide an Http Servlet" in the question makes it a little confusing. If the question had said, "Which abstract class or interface must be extended or implemented to serve HTTP requests", then A would've been correct as a servlet that implements the Servlet interface can serve HTTP requests...
 
Will Myers
Ranch Hand
Posts: 392
Java jQuery Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the subject of this book, personally I find it much easier to read and underdstand than the Head First book which does my swede in. I suppose it depends on how you like to learn.
 
Paulo Aquino
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:As the question stands to me, I also think that the answer should be D, because the question specifically mentions HTTP servlet.

Edit: On a second thought, if we implement Servlet interface to create a servlet, we can serve HTTP requests. The words "provide an Http Servlet" in the question makes it a little confusing. If the question had said, "Which abstract class or interface must be extended or implemented to serve HTTP requests", then A would've been correct as a servlet that implements the Servlet interface can serve HTTP requests...


So the answer is still correct? Its just a matter of correct/appropriate wordings?
 
chandan kumar mitwaa
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One such Question is :

Which of the following classes should a JSP page's servlet class must extend?

a) javax.servlet.jsp.JspPage
b) javax.servlet.jsp.HttpJspPage
......
..) Non of these


Ans is: None of these
The explanation is:

The JSP page need not extend any class. It must, however, implement the Servlet interface [since all jsp pages are ultimately converted into a servlet]

This is the hierarcy of the interfaces:

javax.servlet.Servlet <- javax.servlet.jsp.JspPage <- javax.servlet.jsp.HttpJspPage

Now, the base class of the JSP page, which is provided by the servlet container vendor, implements the javax.servlet.jsp.HttpJspPage interface. If you do not provide the 'extends' attribute of page directive, then this is the class that your jsp page's servlet extends from.




I agree on answer A in Aj's question, because you can build a HTTP servlet class from scratch while implementing the Servlet interface is always mandatory.

Similar is the case with convenience classes SimpleTagSupport, TagSupport and BodyTagSupport used to write custom tags. You can just ignore them at your will.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic