Kendall Ponder wrote:I ran into a problem on the enthuware test which used << which I believe is a bitwise operator.
It's actually a bit shift operator
and it's the signed left shift operator to be more precise. No need to study them! I even wonder if they are covered on the OCP exam.
&& and
|| are known as the conditional operators;
&,
| and
^ are known as the bitwise operators. The conditional operators (which are short-circuit) can only be used with booleans, so you'll see them only in conditions. The bitwise operators are used for bit operations mostly on integral types (byte, short,...) and as their name suggests they do their magic on the actual bits of the value. You could use
&,
| and
^ on 2 booleans as well. Bitwise operators are less commonly used and their bit-twiddling capabilities are
not on the exam. For the exam you only need to know:
bitwise operators existhow they work on booleansthe difference in behavior with the short-circuit operatorsThere's a huge difference between these 2 statements:
Nothing better than a little code snippet to demonstratehow they work on booleans:
Output:
Hope it helps!
Kind regards,
Roel