1. Recap previous week (do yourself at home)

  • Quiz IncrementOperators.java

  • Variables, declaration and initialization

  • Types of errors, compile-runtime-logical

  • Coding conventions

  • Increment / decrement operators

2. Selection statements, boolean expressions and boolean operators

Relational operators
Figure 1. Relational operators [1];

3. Nested if statement and logical operators

  • Nested if ClassifyGrade1.java

  • Nested if improved ClassifyGrade2.java

  • Logical operators !, &&, || , ^^ (XOR).

  • Note the doubling of the char (e.g. &&).

    • && logical: AND, BOTH (ALL)

    • || logical: OR, ANY (at least one)

    • ^^ logical: EXCLUSIVE OR, exactly one, one and one only.

  • Usage of curly braces and indentation, no ;

  • Boolean variable

  • isValid instead of isValid == true

  • Conditional expression with ternary operator

4. Switch statements

  • Example switch case SwitchDemo.java

  • Experiment with question at the bottom

  • Only constant values after case

  • Data type of constants match data type value of switch-expression

5. Debugging

  • Make sure that you’re not looking for a needle in a haystack

  • Start very simple and compile; uncomment suspicious code

6. Existing mathematical functions

Random example
Figure 2. Random example [1];
Random (in general)
Figure 3. Random (in general) [1];

7. char datatype, Character class and operations

8. String class and operations

The characters in a String object can be accessed using its index.
Figure 4. The characters in a String object can be accessed using its index.[1];

9. Formatting console output


1. Liang, Y Daniel. Intro to Java Programming, Comprehensive Version, Global Edition, 10th Edition. Pearson (Intl), 11/2014. VitalBook file.