• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple Mock Exam Clarification - getDateHeader()

 
Kram Nart
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another mock exam question from http://j2eeworld.weebly.com/. I thought the answer would be A, right? How can you stick a long into a String without the compiler complaining about it?!

What will be the output of the following code? Assume that all the variables are declared properly
String str= request.getDateHeader("Accept-Language");
out.println(str);

A Compiler error
B An IO Exception is thrown
C Null
D An IllegalArgumentException thrown

Answer
D
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought the answer would be A, right?

Right.
 
Dee Brown
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the API:

Throws:
java.lang.IllegalArgumentException - If the header value can't be converted to a date
 
Kram Nart
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dee Brown:
Check the API:

Throws:
java.lang.IllegalArgumentException - If the header value can't be converted to a date


I did. I'm aware that that method returns a long and throws the IllegalArgumentException. But my point is that, if we can't get pass the compilation error, how can we get to the IllegalArgumentException.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the API:

Check the returned value
 
Dee Brown
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the returned value


I made a mistake. Believe it or not, it does happen!
 
Marcus Sanchez
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kram Nart:


I did. I'm aware that that method returns a long and throws the IllegalArgumentException. But my point is that, if we can't get pass the compilation error, how can we get to the IllegalArgumentException.



Like you, I don't see how we can get pass the compiler error...
>>Cannot Convert long to String<<
[ June 25, 2008: Message edited by: Marcus Sanchez ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic