Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL mock exam question - what's YOUR answer?

 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

please view the following mock exam question and please answer it with an explanation for your choice



If you know where this question is from, please keep that information for yourself and try to explain it with your own words

Regards,
Darya
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my mind A, B, D, and E should all work. C and F won't work.
Answers A, B, D and E should all work as they are dealing with String objects where String objects are valid, ie properties of MyBean or keys into a Map.

C and F can't convert the 'a' into something meaningful. If there was an attribute with the name 'a' and a numeric value then that is a different story, but without it they wont work.

Mat
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Matt,

What you say would also hold for the answers D and E, so why don't you mention them

Regards,
Darya
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Darya,

I am not sure what you mean, I did mention D and E. I think that A, B, D and E should work and C and F will not


Mat
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Matt,

I don't understand why D and E should work . There is nothing in MyBean about a

Regards,
Darya
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Darya,

D and E will work because params is a java.util.Map therefore the EL interpreter will say give me the params object in MyBean. Ah its a Map therefore look in the Map for an entry under the key "a", which unless you populate the Map with a key of "a" will be null and therefore nothing will get printed.

In effect the EL interpretor is doing the following
Object o = MyBean.getParams();
if(o instanceof Map) {
Map m = (Map)o;
return m.get("a");
}

Does this make sense?

Hope it helps to clear the confusion up

Mat
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I got it

Thanks,
Darya
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A simple answer for this is that C and F don't work because . operator cannot be used for Lists - can be used for only maps and beans. The rest will work, they will never throw an error, they might return null which would be handled gracefully
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Darya,

Where does the question come from ?

Mat
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's from HFSJ p. 423

Regards,
Darya
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic