aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ - Q15 on page 431 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFSJ - Q15 on page 431" Watch "HFSJ - Q15 on page 431" New topic
Author

HFSJ - Q15 on page 431

Chinu Hota
Greenhorn

Joined: Jan 17, 2006
Posts: 14
Can you please explain why C and F are right answers in this question. I can't really understand the explanation given. What is "a"??



Which will cause errors:

A) ${myBean.name}
B) ${myBean["name"]}
C) ${myBean.objects.a}
D) $myBean["params"].a}
E) ${myBean.params["a"]}
F) ${mybean["objects"].a}
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

This question wants to stress about the difference between accessing a Map and a List in EL.
"a" is variable which does not exist. When using a Map, ${myBean["params"].a}, won't because it will search for the key "a" in the map "params", calling containsKey() and get().
However, you can do this with a List only using integers.
Here are the details from the spec:

- expr-a.identifier-b is equivalent to expr-a["identifier-b"];
- Evaluate expr-a into value-a
- Evaluate expr-b into value-b
- If value-a is a Map, List, or array:
- If value-a is a Map:
If !value-a.containsKey(value-b) then return null.
Otherwise, return value-a.get(value-b)
- If value-a is a List or array:
- Coerce value-b to int (using coercion rules)
If coercion couldn't be performed: error

"a" is not an int, so error is produced.


[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HFSJ - Q15 on page 431
 
Similar Threads
EL mock exam question - what's YOUR answer?
Doubt in EL
EL Question from HFSJ
chapter:8,self test-15
HFS question 15 page # 423