wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubt in EL operator 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 "Doubt in EL operator" Watch "Doubt in EL operator" New topic
Author

Doubt in EL operator

Gurukant Desai
Ranch Hand

Joined: Apr 07, 2008
Posts: 56
Hi,
While appearing in Marcus Green's quiz question no.5 of EL chapter
<%int i = 1;int j =2;%>
${i < j}
${1 lt 2}

I was expecting answer as "true true" but right answer is "false true"

Can anyone please explain why ${i < j} will evaluate to false?

Thanks in advance
[ May 06, 2008: Message edited by: Gurukant Desai ]
Musab Al-Rawi
Ranch Hand

Joined: Aug 06, 2007
Posts: 231
hi,

if i am not mistaken
<%int i = 1;int j =2;%>
these are variables not attributes. with the EL you can access attributes of four scopes.
so ${i} and ${j} are not defined ... so they are treated as zero.
So ${0 < 0} that's false because zero is equal to zero.


SCBCD - SCWCD - SCJD - SCJP - OCA
Padma priya Gururajan
Ranch Hand

Joined: Oct 05, 2006
Posts: 434
Hi,
Any correct solutions to the problem?
Thanks in advance.


Padma priya N.G.
Be the change you want to be - Mahatma Gandhi
Kumar Garlapati
Ranch Hand

Joined: Feb 04, 2008
Posts: 38
Musab is absolutely correct with bit change in the explaination, except that zero, it doesn't evaluates as zero. It evaluates as blank.

If it evaluates as zero, ${i==j}, should return true, but it's returning as false. i tried.

output is : true
If we remove scriplet from above code, then output is : false.
it means that if i and j are not present in any scope, they are unable to evaluate as any values. so its evaluating as false.
[ May 06, 2008: Message edited by: Kumar Garlapati ]

Regards,<br />Kumar
Musab Al-Rawi
Ranch Hand

Joined: Aug 06, 2007
Posts: 231
with EL null evaluates to false in boolean expressions and to zero in arithmetic operations.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Doubt in EL operator