6 Conditions and Operators

Oracle Academy Section

Section 5: Conditional Programming

  • Lesson 1: Boolean Expressions and if/else Constructs

  • Lesson 2: Understanding Conditional Execution

  • Lesson 3: switch Statement

Section 5 Quiz

Java Foundations Certification Exam Topics

Using Decision Statements

  • Use the decision making statement (if-then and if-then-else)

  • Use the switch statement

  • Compare how == differs between primitives and objects

  • Compare two String objects by using the compareTo and equals methods

Working with Java Operators

  • Use basic arithmetic operators to manipulate data including +, -, *, /, and %

  • Use the increment and decrement operators

  • Use relational operators including ==, !=, >, >=, <, and <=

  • Use arithmetic assignment operators

  • Use conditional operators including &&, ||, and ?

  • Describe the operator precedence and use of parenthesis

Key Resources

  1. Java Tutorials:

    1. Operators

      1. Assignment, Arithmetic, and Unary Operators

      2. Equality, Relational, and Conditional Operators

      3. Operator Precedence

      4. Summary of Operators

    2. Control Flow

      1. if-then and if-then-else

      2. The switch Statement

  2. Udemy

    1. Lecture 10: "If"

    2. Lecture 13: Switch

  3. Bucky's Room

    1. Math Operators (5:29) int, operations on ints always result in ints, + - * / %

    2. Increment Operators (5:08) ++, pre vs post. --, +=

Supplemental Resources

Most Important Concepts / Code

+ will add if there are numbers on both sides.

+ will concatenate if there is a String on at least one side.

Each data type is also a class that contains methods for doing operations with the types like Double.intValue

Equality and relational operators: determine if one operand is greater than, less than, equal to, or not equal to another operand. Use == for equal to.

Conditional (logical) operators: && and ||

You cannot use == with strings.

Use a trailing else or default case to handle all possible cases.

if (testscore >= 90) {

grade = 'A';

} else if (testscore >= 80) {

grade = 'B';

} else if (testscore >= 70) {

grade = 'C';

} else if (testscore >= 60) {

grade = 'D';

} else {

grade = 'F';

}

System.out.println("Grade = " + grade);


int value1 = 1;

int value2 = 2;

if((value1 == 1) && (value2 == 2))

System.out.println("value1 is 1 AND value2 is 2");

if((value1 == 1) || (value2 == 1))

System.out.println("value1 is 1 OR value2 is 1");

Hour 1

Hour 2

  • Relational and Conditional

  • Conditional (ternary) ? operator

  • Trailing else / Default case

  • Equality vs. Assignment

  • Flowcharts - Logic Ch 4

  • Make Integration project menu driven - Logic Ch 11