Operator

Assignment Operator

The assignment operator "=" assigns the value on its right to the operand on its left:

int cadence = 0;
int speed = 0;
int gear = 1;

Arithmetic Operators

OperatorDescription
+Additive operator (also used for String concatenation)
-Subtraction operator
*Multiplication operator
/Division operator
%Remainder operator

Unary Operators

OperatorDescription
+Unary plus operator; indicates positive value (numbers are positive without this, however)
-Unary minus operator; negates an expression
++Increment operator; increments a value by 1
--Decrement operator; decrements a value by 1
!Logical complement operator; inverts the value of a boolean

Relational Operators

OperatorDescription
==equal to
!=not equal to
>greater than
>=greater than or equal to
<less than
<=less than or equal to

Conditional Operators

OperatorDescription
&&and
||or

These operators exhibit "short-circuiting" behavior, which means that the second operand is evaluated only if needed.

Ternary operator

?:is known as the ternary operator because it uses three operands.

If someCondition is true, assign the value of value1 to result. Otherwise, assign the value of value2 to result.

result = someCondition ? value1 : value2;

Type Comparison Operator

The instanceof operator compares an object to a specified type.

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

Operation on bits

~

The unary bitwise complement operator "~" inverts a bit pattern.

  1. it can be applied to any of the integral types, making every "0" a "1" and every "1" a "0".
  2. For example, a byte contains 8 bits; applying this operator to a value whose bit pattern is "00000000" would change its pattern to "11111111".

<<

The signed left shift operator "<<" shifts a bit pattern to the left, and the signed right shift operator ">>" shifts a bit pattern to the right. The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand. The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension.

&

The bitwise & operator performs a bitwise AND operation.

^

The bitwise ^ operator performs a bitwise exclusive OR operation.

|

The bitwise | operator performs a bitwise inclusive OR operation.

Last updated on