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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "EL . and [] operators" Watch "EL . and [] operators" New topic
Author

EL . and [] operators

Paul Statham
Ranch Hand

Joined: Dec 05, 2008
Posts: 48
I have a query about a question in the HFSJ book


Which about EL access operators are true?

a. Anywhere the . (dot) operator is used, the [] could be used instead.
b. Anywhere the [] operator is used, the . (dot) could be used instead.
c. If the . (dot) operator is used to access a bean property but the property doesn't exist, then a runtime exception is thrown.
d. There are some situations where the . (dot) operator must be used and other situations where the [] operator must be used.


Now the answers are A + C. I chose A, C + D. It lists the reason for D not being correct as


Option D is incorrect because the dot operator can always be converted to the [] operator


Whilst it's true that the [] operator can be used for JavaBeans, Maps, Lists and Arrays. It's not true that the . (dot) operator can be used for Lists and Arrays. So there are some situations where you shouldn't use the . (dot) operator, so therefore D is a valid option. Am I right?
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1696
    
  25

Hi Paul,

So there are some situations where you shouldn't use the . (dot) operator, so therefore D is a valid option. Am I right?

These questions are always tricky and sometimes they could be ambigious, but in your reasoning you have found:

  • that the [] operator must be used with a list or an array
  • but
  • you haven't found the situation that the . operator must be used because the [] operator fails to work

  • that is why D is not correct

    Regards,
    Frits
    Paul Statham
    Ranch Hand

    Joined: Dec 05, 2008
    Posts: 48
    Ah ok I see it's all in the word must! Dot is Never a must!
    bhanu chowdary
    Ranch Hand

    Joined: Mar 09, 2010
    Posts: 256
    Paul Statham wrote:Ah ok I see it's all in the word must! Dot is Never a must!

    That is the catch . You can always replace a "." with []
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: EL . and [] operators