This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

EL doubt

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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..
 
Greenhorn
Posts: 8
IntelliJ IDE Netbeans IDE Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Honk if you love justice! And honk twice for tiny ads!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic