Multiple choice technology programming languages

Which of the following servlet methods can return null? (Choose one.)

  1. getInitParameterNames()

  2. getInitParameter(String name)

  3. getServletName()

  4. getServletContext()

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

getInitParameter(String name) returns null if the requested parameter does not exist. The other methods (getInitParameterNames returns an Enumeration, getServletName returns a String, getServletContext returns a ServletContext) never return null.

AI explanation

getInitParameter(String name) looks up a named init parameter and returns null if no parameter with that name was configured for the servlet. The other methods listed always return a non-null value: getInitParameterNames() returns an (possibly empty) Enumeration, getServletName() returns the configured servlet name, and getServletContext() always returns the context object.