wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Empty Servlet Class - Niko's mock exam question 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 "Empty Servlet Class - Niko Watch "Empty Servlet Class - Niko New topic
Author

Empty Servlet Class - Niko's mock exam question

Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

This question is from "Niko's Free SCWCD Mock Exam for Servlets"

18.What happens when we compile and deploy this servlet? (1 correct answer)
public class Test extends HttpServlet {

}
a.Compilation fails because there is no init() method defined.
b.An exception is thrown at runtime because service() has no method to call!
c.Deployment succeeds but we get a message 'GET is not supported by this URL' if we access it.

The answer given is c. I was thinking it would be b, since a ServletException would be thrown. (Also, not sure if the two answers are mutually exclusive. Wouldn't the accurate answer be "Deployment succeeds, but an exception is thrown at runtime because service() has no method to call.")


"A problem well stated is a problem half solved.” - Charles F. Kettering
SCJP 6, OCPJWCD
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Hi Nidhi!

The doGet(-), doPost(-), ... methods doesn't need to be provided to compile and execute your Servlet if you extend the HttpServlet class.

In the matter of fact, what you normally do is override methods previously defined in HttpServlet itself. Therefore, the service() always knows what method to call - it just uses the very basic implementation from the super class (HttpServlet) which returns 'Operation not supported' type of information.


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

Thanks a lot. That really makes it clear.
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Glad I could help :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Empty Servlet Class - Niko's mock exam question