Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Double wrapper class doubt?

 
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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 Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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 Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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 Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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 Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry,

Thanks for the help.
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic