• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

EL doubt

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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 ]
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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� ]
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
     
    Ranch Hand
    Posts: 115
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,

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

    Kathir
     
    Charles Lyons
    Author
    Posts: 836
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 177
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you but still i m confused about it .
     
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,

    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 don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
    Devious Experiments for a Truly Passive Greenhouse!
    https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
      Bookmark Topic Watch Topic
    • New Topic