• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Double wrapper class doubt?

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

The code below is also from Dan Chisholm,



Help me out guys with the commented line above?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll start you off:


Looking at the API for Double, I see that isNaN returns a boolean. So on the lefthand side of == must be a boolean. It can only be the result of v != v.

So we have:


Now you look at the Double API to see what the result of v != v is (where v is NaN). It's in the description of Double.NaN.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry,

I knew that NaN is not equal to anything and when we say NaN == NaN returns false and NaN != anything will return true. My confusion was on how to group the operators like you showed by placing braces...

(v != v) == Double.isNaN(v)...

But still I want to know based on what rules we group the operators??

Thanks for the help.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jothi Shankar Kumar Sankararaj:
Barry,

I knew that NaN is not equal to anything and when we say NaN == NaN returns false and NaN != anything will return true. My confusion was on how to group the operators like you showed by placing braces...

(v != v) == Double.isNaN(v)...

But still I want to know based on what rules we group the operators??

Thanks for the help.



== and != operators have equal precedence. And for equal precedenct operators execution happens from left to right.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help. So concluding, when there are two or more equal precedence operators in a statement, then the execution happens from left to right.

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

Satish Kota writes..
== and != operators have equal precedence. And for equal precedenct operators execution happens from left to right.



Satish,What about logical operators?

Jothi,Is this question is from mock for 1.4?Because I guess operator precedence is not a part of SCJP 5.0 exam.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sanjeev,

I'm aiming for 1.4 version. So the question is for 1.4 exam.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jothi, this is all very basic stuff. I get the impression you are not referring to any basic Java book where these topics are explained rather early on. Are you not, in fact, reading an introductory book on Java? (I do not refer to K & B because it expects its readers to have already learnt Java).

Anyway, operator precedence and association is very well presented on Roedy Green's Java Glossary Site
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry,

Thanks for the help.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic