This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Numeric Null Comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Numeric Null Comparison" Watch "Numeric Null Comparison" New topic

Numeric Null Comparison

Marc LeClerc

Joined: May 10, 2007
Posts: 14
I have the following if statement which is gagging on me:

The not null condition works fine, but when trying to see if both are null,
the IDE gives me the following

The operator type && is undefined for the argument type(s) null, boolean

I am VERY new to java and am just trying to tweak some existing code for a vacationing colleague.

Any and all help appreciated.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

This looks suspect:

are those single equals? If they are you are trying to do assignment, not checking their value.
[ April 21, 2008: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

Yes, use "==" for comparison, not '='.

[Jess in Action][AskingGoodQuestions]
Ravikanth kolli
Ranch Hand

Joined: Feb 10, 2008
Posts: 179

are num1 and num2 integers as the topic says numeric null comparision?

Marc LeClerc

Joined: May 10, 2007
Posts: 14
Yes they are integers, the == seemed to have fixed it.

Thanks for not pouncing on the newbie !
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Yes, you're comparisons are faulty, but that will just make it work incorrectly once you get it compiled.

It's not compiling, because you're missing a set of parentheses.

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
I agree. Here's the link:
subject: Numeric Null Comparison
It's not a secret anymore!