JBridge

JBridge: Certification Question Of The Day

JBridge Home >> Certification Questions >> Question for Saturday 31st May 2003 Saturday 31st May 2003

Which of the following sets of statements should compile successfully within a JSP? (2 correct answers)



A 
<%@ page import = "java.util.*" %>
<% Enumeration e = application.getInitParameterNames(); %>

B 
<%@ page import = "java.util.*" %>
<% Vector v = application.getInitParameterNames(); %>

C 
<% Object o = application.getAttribute("My Attribute"); %>

D 
<% long l = application.getMinorVersion(); %>

E 
<% String s = application.getMimeType(); %>

Page down for the answer...











































The Answer

A and C will compile successfully, so are the correct answers.
The question revolves around the application JSP implicit variable, which is an instance of a class implementing the ServletContext interface. All the answers use legitimate methods from ServletContext, though not always with the correct parameters or return types.
getInitParameterNames() returns an Enumeration, not a Vector (so answer A is right and B is wrong).
getMinorVersion() (answer D) returns an int, not a long; there aren't that many revisions of the servlet API anticipated!
getMimeType() takes a parameter - a String - which tells the method which file to examine in order to return a mime type. So E is false.


EMail: dbridgewater@jbridge.co.uk
Phone: +44 (0)1943 877414
Fax: +44 (0)1943 877414
Mail: David Bridgewater, Willow Dene, Bradford Road, Menston, Ilkley, West Yorkshire, LS29 6ED, UK
Copyright © 2003 David Bridgewater. All rights reserved.