aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes EL doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "EL doubt" Watch "EL doubt" New topic
Author

EL doubt

narendra bhattacharya
Ranch Hand

Joined: Feb 17, 2010
Posts: 66


a It will print 1 because the statement is valid.
b It will print 2 because the statement is valid.
c It will throw an exception because a is undefined.
d It will throw an exception because the expression’s syntax is invalid.

and the ans is a..

can smbody help me in this..
also if i replace a by "a" it will give give ERROR..


SCJP1.6,SCWCD1.5
Herman Pomstra
Greenhorn

Joined: Aug 17, 2011
Posts: 7

EL treats undefined variables as null or zero. So "5 + 3 + a" evaluates to "5 + 3 + 0". This is > 0 so 1 is printed.

Regards
Herman
narendra bhattacharya
Ranch Hand

Joined: Feb 17, 2010
Posts: 66
Herman Pomstra wrote:EL treats undefined variables as null or zero. So "5 + 3 + a" evaluates to "5 + 3 + 0". This is > 0 so 1 is printed.

Regards
Herman


Thanks Herman
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1696
    
  25

also if i replace a by "a" it will give give ERROR..


That is correct, "a" is a String that does not represent a number and cannot be translated into a number like for instance "15".
${"Not a Number" + 3} will evaluate in a javax.servlet.jsp.el.ELException

If you use:
${(5 + 3 + a > 0) ? 1 : 2}
the EL-parser will try to find an attribute in one of the 4 scopes named 'a' and if it is not found it will be treated as an 0 or null like Herman is saying (@ Herman congratulations on your result!)

Have a look at some EL examples in my notes (ScwcdLinks)

Regards,
Frits

 
jQuery in Action, 2nd edition
 
subject: EL doubt