aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Arithmetic value of 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 "Arithmetic value of "" in EL expressions" Watch "Arithmetic value of "" in EL expressions" New topic
Author

Arithmetic value of "" in EL expressions

Bindu Lakhanpal
Ranch Hand

Joined: Oct 17, 2008
Posts: 171

In Enthware mock question "com.enthuware.ets.scwcd.v5.2.179"
It is stated in answer and explanation that EL expression
${requestScope['none'] eq 0} will return true.The reason given is : "" is interpreted as 0.
But I got false as its output (line 1)




output is:

ge true
gt true
eq false
and false
not true
value


Can someone please explain this output and hence the arithmetic value of "".

Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3855

Bindu Lakhanpal wrote:Can someone please explain this output and hence the arithmetic value of "".

EL is "null" friendly. But "" is not null so you will get a NumberFormatException. Try commenting the line "request.setAttribute("none",""); " and you will get the output as "1" for the "${requestScope['none'] + 1}" statement as EL treats the null attribute as 0.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Bindu.
But I got false as its output (line 1)

I tested this in Tomcat5.5.9, Firefox3.5 and I got 'true'.
${requestScope['none'] eq 0} will return true.The reason given is : "" is interpreted as 0.

I am not getting how "" is interpreted as 0. Can you please explain?
Bindu Lakhanpal
Ranch Hand

Joined: Oct 17, 2008
Posts: 171

I am using Tomcat 6.0.18. And i got "false".
Hasnain Javed Khan
Ranch Hand

Joined: Nov 23, 2007
Posts: 73
Hello Bindu.

The following is quoted from the JSP 2 Specs

JSP.2.8.3 Coerce A to Number type N
• If A is null or "", return 0.


Hope that helps.

Kind Regards.

Hasnain.

Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Hasnain.

JSP.2.8.3 Coerce A to Number type N
• If A is null or "", return 0.


Can you please explain how got '0', its underlying mechanism?
Bindu Lakhanpal
Ranch Hand

Joined: Oct 17, 2008
Posts: 171

Hi Hasnain ,
Yes.It helped.Thanks.So it means Tomacat 6.0.18 is not behaving as expected from specificaton.And Tomcat 5.5.9 was behaving as expected.
Anyway, i know what is correct for the exam.Its always what spec says.
Hasnain Javed Khan
Ranch Hand

Joined: Nov 23, 2007
Posts: 73
Hi Chinmaya,

Chinmaya Chowdary wrote:Hi Hasnain.

JSP.2.8.3 Coerce A to Number type N
• If A is null or "", return 0.


Can you please explain how got '0', its underlying mechanism?


Sorry but 'm afraid I did not get your question.

Well....From the top of my head



Is this what were you asking ?

Kind Regards.
Hasnain Javed
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Chinmay, read the specs, its given in the specs, for relational operators, if one of the operand is a number, the second is converted into a number too, in that if the second operand is null or empty string, then its converted to 0. Read this page. Specifically these parts

coerce A to Number type N
A is null or ""
return 0


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Bindu Lakhanpal
Ranch Hand

Joined: Oct 17, 2008
Posts: 171

Chinmaya, can you please check the output of following line in tomcat 5.I am just curious. It should return 1 according to specs.Right?

${requestScope['none'] + 1}
Dumitru Postoronca
Ranch Hand

Joined: May 06, 2008
Posts: 46
Bindu Lakhanpal wrote:So it means Tomacat 6.0.18 is not behaving as expected from specificaton.And Tomcat 5.5.9 was behaving as expected.
It means that for SCWCD exam you should use Tomcat 5.5 as the book says.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Thankyou Hasnain, Ankit.

From now onwards I will read specifications. During my preparation of SCWCD, I studied only HFSJ. I might have to read specifications also inorder to get deeper sense of subject.
Bindu Lakhanpal wroteChinmaya, can you please check the output of following line in tomcat 5. I am just curious. It should return 1 according to specs.Right?

${requestScope['none'] + 1}

I tested this in Tomcat5.5.9, it returns 1.
Dumitru Postoronca wroteIt means that for SCWCD exam you should use Tomcat 5.5 as the book says.

Yes, we should use.
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Wow... this is was an informative discussion!

I am getting a Jasper Exception for <% ${requestScope['none'] + 1} %> using TomCat 5.5.

Is this the expected answer?


The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Wow... this is was an informative discussion!

Yes, but you're out of subject here. You're trying to write non-java code in a scriptlet.


[My Blog]
All roads lead to JavaRanch
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
oops.. that was an honest mistake!

Got the right answer!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Chinmaya Chowdary wrote:
I tested this in Tomcat5.5.9, it returns 1.

It also returns 1 in Tomcat 6.0.14.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arithmetic value of "" in EL expressions