![]() |
JBridge: Certification Question Of The Day |
| JBridge Home >> Certification Questions >> Today's Question | Sunday 4th May 2003 |
|
A browser sends a request containing no headers to a servlet. What is
the result of executing the following method within the servlet? protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
long l = request.getDateHeader("Date");
Date d = new Date(l);
System.out.println(d);
}
A “null” is output to the console. B A date is output to the console. C A NumberFormatException is thrown. D A compilation error occurs. E A DateHeaderException is thrown. F An IllegalArgumentException is thrown. Page down for the answer... The AnswerThe correct answer is B – a date is output to the console. When
getDateHeader() receives a header name that isn’t in the request, it
returns a -1 long value. -1 is a valid date as far as the Date constructor
is concerned. On my system, the date printed out is 1 second before one
o’clock on Thursday 1st January 1970 (Greenwich Mean Time). |
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.