1. Writing a simple program

  • Problem - algorithm - pseudocode (compute area of a circle)

  • Build up Java solution

  • First without input (see ComputeArea.java)

  • Then with input using Scanner (see ComputeAreaWithConsoleInput.java) and explain

    • import (with/out wildcard)

    • Create a new Scanner object

      • In Chapter 9 we will learn more about objects

    • Read a double

    • Print

      • + as a String concatenation operator

      • print vs. println

2. Variables (for storing values in the memory)

  • Values stored in a variable can be changed (therefore they are called variables)

  • Explain using ComputeArea.java

  • Variable declaration

  • Representing data of a certain type, a.k.a. Data types, e.g. int and double

  • Variable declaration and initialization at once

  • Assignment statements

    • Assignment operator =

    • Expressions

    • Assignment expression (e.g. System.out.println(x = 1);)

3. Named constants (final)

  • Add constant to ComputeArea (see ComputeAreaWithConstant.java)

    • Naming convention: capitalize every letter in a constant (see below for more naming conventions)

4. Naming conventions

  • Variables and methods: use lowercase for variables and methods. Consider CamelCase

  • Classes: capitalize first letter in a class name (and use class name as file name)

  • Constants: capitalize every letter in a constant!

5. Numeric data types and operations

  • Integer types: byte, short, int and long (ask student to lookup difference)

  • Floating-point types: float and double

  • Integer division

  • Remainder/modulo operator: %

  • Show DisplayTime.java

Modulo example
Figure 1. Example of the modulo operator [1];

6. Increment ++ and decrement -- operators

  • Postincrement vs. preincrement

1. Copied from Imgur