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 != operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "!= operator" Watch "!= operator" New topic

!= operator

venkatesh badrinathan
Ranch Hand

Joined: Aug 03, 2008
Posts: 77
void assertTest(Object obj) {
assert obj != null : throw AssertionError();
REASON: Second operand must evaluate to an object or a primitive. (It can also be null.)
My question: what is that != operator. i know only ? operator to be used there. can anyone explain please.. Thanks for you in advance

Ronald Schild
Ranch Hand

Joined: Jun 09, 2008
Posts: 117
It is the operator that tests for unequality.

More information from SUN.
[ August 05, 2008: Message edited by: Ronald Schild ]

Java hobbyist.
Sandeep Bhandari
Ranch Hand

Joined: Apr 16, 2004
Posts: 201
The semi colon : is for displaying additional info which is supplied by expression/function appearing after the semi colon.

Note: You can't call a function that has returns type of void.

SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
marc weber

Joined: Aug 31, 2004
Posts: 11343

An assertion has the form...

assert booleanExp;


assert booleanExp : expression;

If the booleanExp of an assertion is false, then an AssertionError is thrown at runtime. If the second form is used (with the colon and expression), then the expression is passed to the constructor of the AssertionError where it's converted to a String message.

As explained above, != is a relational operator meaning "not equal to." So the line...

assert obj != null; asserting that "obj" is not a null reference.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
venkatesh badrinathan
Ranch Hand

Joined: Aug 03, 2008
Posts: 77
Thank you Mr.Marc.. i have understood now.
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
yes, don't confuse this with the ternary operator

boolean expr ? casetrue : casefalse

that is totally different from the boolean test in an assert.

SCJP - 86% - June 11, 2009
I agree. Here's the link:
subject: != operator
It's not a secret anymore!