It's not a secret anymore!
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Redundant methods? 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 "Redundant methods?" Watch "Redundant methods?" New topic

Redundant methods?

Aruna Raghavan
Ranch Hand

Joined: May 14, 2002
Posts: 194
Hi ranchers,
I don't understand why the getInitParameter(String name) and getInitParameterNames() are on both ServletConfig and ServletContext interfaces.
Also, if the HttpServlet extend Generic Servlet that implement StervletConfig why have a method on the HttpServlet to getServletConfig()? Why is there such redundancy?

Aruna A. Raghavan<br />SCJP, SCJD, SCWCD
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3635
ServletConfig (only meant for a servlet) and ServletContext (meant for the whole web app) have different initialization parameters. So both need to have their own getInitParameter() method.
getServletConfig() method is declared in the Servlet interface therefore anybody (and thus GenericServlet also) who implements that interface has to define it.
However, ServletConfig is an interface. So to provide a simple implementation of it, they've made GenericServlet implement it. This is just for the ease of the developers. They could as well have another class say GenericServletConfig that could provide simple implementation of ServletConfig.

Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
I agree. Here's the link:
subject: Redundant methods?
It's not a secret anymore!