loader image
Skip to main content
If you continue browsing this website, you agree to our policies:
x

Topic outline

  • Unit 4: Relational and Logical Operators in Java

    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.

    • Upon successful completion of this unit, you will be able to:

      • explain relational operators such as >,>=, <, <=, ==, and !=;
      • write Boolean expressions using relational operators;
      • use logical operators such as &&, ||, and !; and
      • evaluate truth-tables.
    • 4.1: Relational and Logical Operators

      • 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().

      • Objects that have an ordering are compared using the compareTo() method.

      • 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.

    • 4.2: Truth Tables

      • Read this chapter, which discusses Boolean variables as used in decision tables. Truth tables are used to collect variables and their values relative to decisions that have to be made within control structures.
      • 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.

    • Unit 4 Assessment

      • Take this assessment to see how well you understood this unit.

        • This assessment does not count towards your grade. It is just for practice!
        • You will see the correct answers when you submit your answers. Use this to help you study for the final exam!
        • You can take this assessment as many times as you want, whenever you want.