File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

EL doubt

Vishal Chugh
Ranch Hand

Joined: Oct 27, 2007
Posts: 177

Howcome : ${100 < 2 div 0} -true ???

It should have been evaluated as ${100 < infinity } and then infinilty being unknown , should have been zero then it becomes ${100 < 0 } then it should return false .

Please guide

[ December 28, 2008: Message edited by: Vishal Chugh ]
Mamadou Touré
Ranch Hand

Joined: Dec 27, 2007
Posts: 189

Infinity is greather than any number you can imagine, so 100 < infinity is always true.

hope this will help
[ December 28, 2008: Message edited by: Mamadou Tour� ]

SCJP 5 (76%)
SCWCD 5 (86%)
SCBCD 5(70%)
"The greatest glory in living lies not in never falling, but in raising every time we fall.".. Nelson Mandela
Charles Lyons
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
Please use a meaningful subject line.

You need to know three basic sets of rules about EL to analyse these problems:
  • Operator precedence
  • Type coercion
  • How operators behave with "unusual" or out-of-range values
  • You can find both in the JSP specifications. Let's apply these rules in order:
  • The precedence check tells us % has higher precedence than <, so bracket the expression like this: 100 < (2 % 0)
  • Type coercion tells us both sides of the % operator are cast to a long with the integer mod operator then applied (the type coercion is obvious here)
  • Knowing (from basic Java syntax) that A % 0 throws an ArithmeticException for any A means the resulting expression results in an EL error
  • So I would say the expression ${100 < 2 div 0} results in an error... Where did this come from, and have you tried it? If so, in what container?

    I doubt anything as complicated as this would come up on the exam, though it's possible some simple operator precedence and obvious type coercion similar to this would be asked about.
    [ December 28, 2008: Message edited by: Charles Lyons ]

    Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
    Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
    Kathiresan Chinna
    Ranch Hand

    Joined: Aug 17, 2008
    Posts: 115

    I tried this EL in Tomcat 6.0.18,
    ${100 < 2 div 0} => true

    Charles Lyons
    Ranch Hand

    Joined: Mar 27, 2003
    Posts: 836
    For some reason I read that as the modulus operator rather than "div"

    So now I've regained my ability to read EL:
  • Precedence says do 100 < (2 div 0)
  • The div operator casts both arguments to double and then divides in the normal way
  • 2.0/0.0 gives Double.POSITIVE_INFINITY which is > 100 (according to the JLS definition), so the expression is true overall
  • Note the second observation is important and non-obvious: if EL coerced the div operands to long instead, there would have been an ArithmeticException. However, EL always coerces to doubles when doing division. This makes it impossible to do integer arithmetic in a straight-forward manner (which can occassionally be a nuisance).
    ${100 < infinity } and then infinilty being unknown
    You are misunderstanding things here. The result of ${ 100 < (2/0) } does not resolve to the same as ${ 100 < infinity } since EL doesn't have an "infinity" literal---it isn't defined and would be treated as a scoped attribute (EL variable). However, the expression does indeed resolve to the numerical value (double primitive or Double object) of infinity on the right hand side of the < operator---there is no way to type this directly in an EL expression, but it is possible to get this value in a calculation (e.g. by division by zero). Then "100 < +infinity" is true (by JLS rules).
    [ December 28, 2008: Message edited by: Charles Lyons ]
    Vishal Chugh
    Ranch Hand

    Joined: Oct 27, 2007
    Posts: 177
    Thank you but still i m confused about it .
    Chithra Salam

    Joined: Mar 21, 2006
    Posts: 19

    EL is different from java. In java divide by 0 will throw error , but in EL divide by 0 will give result as infinity. You can try ${100/0)} .

    Also div or / are EL function available.
    I agree. Here's the link:
    subject: EL doubt
    jQuery in Action, 3rd edition