0% found this document useful (0 votes)
7 views4 pages

37 Slides IntelliJ Basics Assignment Operator Vs Equals To Operator

Uploaded by

Ines Masmoudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

37 Slides IntelliJ Basics Assignment Operator Vs Equals To Operator

Uploaded by

Ines Masmoudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Difference Between the Assignment and Equal to

Operators

As you can see, we've used the assignment operator (one equal sign) in the if
statement.
What we need to do, is to use the "equals to" operator (two equal signs).

COMPLETE JAVA MASTERCLASS


Assignment Operator VS Equals to Operator
Difference Between the Assignment and Equal to
Operators

This is what the code should look like:

We're not assigning a value here, instead we want to test if the values are equal to
each other.

COMPLETE JAVA MASTERCLASS


Assignment Operator VS Equals to Operator
The NOT
Operator
The exclamation mark (!), or NOT operator, is also known as the Logical
Complement Operator.
It can be used with a boolean variable, to test for the opposite value.

In the code above, we are testing if the value in is car is true. As you can see on the
previous line, we assigned it to be false.

If we use the "not" operator, we are testing for the opposite value of the is car
variable. We assigned is car on the previous line to false, so not is car, would return
true.
COMPLETE JAVA MASTERCLASS
Assignment Operator VS Equals to Operator
The NOT
Operator
I'd generally recommend using the abbreviated form, if your variables are booleans,
for two reasons.
One, It's much harder to identify the error, if you accidentally use an assignment
operator.
As we saw, IntelliJ won't flag this as an error when you're testing a boolean variable,
so the only way you'll know you made this common mistake is by discovering your
program or output isn't what you expected.
Secondly, the code is more concise, and more concise code can often be more
readable code.

COMPLETE JAVA MASTERCLASS


Assignment Operator VS Equals to Operator

You might also like