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 ]

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

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 / AmazonAmazon UK )

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

Kathir

Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836

posted

0

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 ]