File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrapper Classes. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrapper Classes." Watch "Wrapper Classes." New topic

Wrapper Classes.

Jui Mahajan
Ranch Hand

Joined: Jun 02, 2003
Posts: 62
The following question from dan's single topic exam:
class D {
static boolean m(double v) {
return(v != v == Double.isNaN(v));
public static void main (String args[]) {
double d1 = Double.NaN;
double d2 = Double.POSITIVE_INFINITY;
double d3 = Double.MAX_VALUE;
System.out.print(m(d1) + "," + m(d2) + "," + m(d3));
the ans is true, true true. I expected it to be false , true, true, because, in first case, v==Double.isNaN(v)is true and therefore, v!=v is flase.
Pls clarify

-----jui<br />scjp1.4
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
I believe the answer to your question lies in the order in which these operands are evaluated. First, we evaluate v != v, which returns true because Double.NaN is not equal to Double.NaN. Next, we take that result (true) and compare it to the result of Double.isNaN(Double.NaN). That also returns true. Therefore, we finally check to see if true is equivalent to true, which, obviously, it is, and we get a final returned value of true.
I hope that helps,

SCJP Tipline, etc.
Dan Lastoria
Ranch Hand

Joined: Jan 30, 2002
Posts: 57
I think your confusion might simply lie in this least mine did!!

[ August 18, 2003: Message edited by: Dan Lastoria ]
Jui Mahajan
Ranch Hand

Joined: Jun 02, 2003
Posts: 62
Thank you, I guess that solves the problem.
I agree. Here's the link:
subject: Wrapper Classes.
jQuery in Action, 3rd edition