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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "EL Question from HFSJ" Watch "EL Question from HFSJ" New topic
Author

EL Question from HFSJ

Amruth Puppala
Ranch Hand

Joined: Jul 14, 2008
Posts: 295
This question is from HFSJ in chapter 8

public class MyBean{
private java.util.Map params;
private java.util.List objects;
priavte String name;

public java.util.Map getParams() { return params;}
public String getName() { return name;}
public java.util.List getObjects() { return objects;}

}

which will cause errors(assume that an attribute names mybean can be found, and its type is MyBean)? (choose all that apply)

A.${mybean.name}
B.${mybean["name"]}
C.${mybean.objects.a}
D.${mybean["params"].a}
E.${mybean.params["a"]}
F.${mybean["objects"].a}

My answer is CDEF

but the book answer is CF

Please help it understanding this question.


SCJP 5 |SCWCD 5| Started thinking about Web Services ?
Craig Suchanec
Greenhorn

Joined: Feb 25, 2008
Posts: 2
This question is about the difference between accessing elements of a List vs. accessing elements of a Map in EL.

The answer is C & F and they both fail for the same reason. There is no method called "a" for a List object and you cannot access element "a" of a list so an error will occur because the system will not be able to access it.

The reason that D & E do not create errors is that when you use try to access "a" for a map, it will look for an element with the key of "a". If no element with the key of "a" is found it will just return null, which does not cause an error in EL.
Amruth Puppala
Ranch Hand

Joined: Jul 14, 2008
Posts: 295
Awesome explanation Craig Suchanec
Really thank you so much ..I got very clarity now.
Amit Prakash Singh
Ranch Hand

Joined: May 11, 2006
Posts: 38
what about the fact that . dot operator can not be used with the list and array. In both D & F, . is being used for accessing something from the list.


Amit Prakash Singh<br /> <br />SCJP 1.4 93% <br />SCWCD1.5 85%
Bryan Basham
author
Ranch Hand

Joined: Apr 30, 2001
Posts: 199
Originally posted by Amit Prakash Singh:
what about the fact that . dot operator can not be used with the list and array. In both D & F, . is being used for accessing something from the list.


Actually, in option D the dot operator is being used on a Map.

In option F, the dot operator is being used on a List; and as Craig mentioned, this is why option F is one of the correct answers ("it will cause an error").

Make sense?

Cheers,
Bryan
Vishal Chugh
Ranch Hand

Joined: Oct 27, 2007
Posts: 177
Hi,

Thanks , i had also same doubt , now i am bit fine now but still has some doubt.

I undertood it like (Reason for CF being wrong) :
Its not about the non-existance of "a" as method in List object (as said in this post), its about wrong usage of dot operater as its not allowed to use dot operater with list as book says for example it was bit the same case as if i am trying to access {musicList.1}

Please correct me otherwise.

[sorry for reinitiating the thread ]

Thanks
Vishal Chugh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL Question from HFSJ