From the course: Oracle Java Certification: 2. Operators and Decision Statements

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Binary operators

Binary operators - Java Tutorial

From the course: Oracle Java Certification: 2. Operators and Decision Statements

Start my 1-month free trial

Binary operators

- [Instructor] Most Java operators are binary operators. They perform arithmetic, logical, and relational operations. The last three binary operators listed in this table are bit shift operators. They're unique because they are only applicable to integer types, and they directly manipulate the underlying bit patterns of integers. The right shift operation has two variations: arithmetic shift and logic shift. In this example, we take some integer values and simply shift them to the left or right by one bit. What do you think this code would output? The first two statements shift one and negative one to the left by one bit. As the result, the one becomes two and negative one becomes negative two. Generally, we can use a single left shift to achieve a multiplication by two operation. The next two outputs demonstrate that a single right shift can perform a division by two operation. So far, so good, but it doesn't always work…

Contents