In this unit, we discuss relational and logical operators in Java, which provide the foundation for topics like control structures that we will discuss later in the course. In this unit, we start by taking a look at operator notation. We then discuss relational operators as they apply to both numeric operands and object operands. The unit concludes with an introduction to logical operators. By the end of this unit, you should be able to perform comparisons and logic functions in Java and have a fundamental understanding of how they are employed.
Completing this unit should take you approximately 5 hours.
This chapter introduces relational and logical operators. It also discusses the use of these operators to write Boolean expressions.
This chapter goes into more depth about relational and logical operators. You will have to use these concepts to write complex programs that other people can read and follow.
The relational operations on primitive data are ==, >=, <=, >, <, and !=. They compare two data values, when those values' type has an ordering. For example, integers are ordered by size or magnitude. The result of a relational operation is a boolean value: either True or False. The relational operators on objects like Strings are different, and they are expressed as methods. Pay special attention to the equality method, equals().
Complete this review exercise. Think of the response to fill in the blank or to answer true/false, or write your response down. Then, click on the box to reveal the answer to each question.
Answer the questions in this review. After you have thought of your answer, only then click on the box in each question to reveal the correct answer.
Take this assessment to see how well you understood this unit.