Java Notes

Overview of Introductory Programs

What is an "Introductory Program"?

No OOP, no GUI. These programs are classified as introductory because they don't handle the advanced topics such as Object-Oriented Programming (OOP) and Graphical User Interface (GUI) programing.

Why delay OOP? Some advocate an "objects first" approach, but my experience has been that students struggle with the OOP issues, and this is not helped by the unmotivating and impractical examples that are usually used.

Why delay GUI? Java makes introductory GUI programming complicated and difficult. There is no reason it should be that hard for simple programs, but it is. So it's generally not taught at the beginning. Too bad, because it doesn't need to be hard.

Organized by flow

Control flow often is used to order the teaching of topics. Control flow can be taught in many orders, but for these example programs it's in the order:

  1. Sequential flow.
  2. Conditional flow (if, switch)
  3. Loop flow (while, for, do-while)
  4. Method calls.
  5. Exceptions.

1. Sequential Flow (emphasis on basic structure, types, variables, IO)

  1. Output comment
    • Example
    • Purpose
      • Basic structure: class definition, main definition, braces, indentation, semicolons.
      • Flow: Sequential from top to bottom.
      • Output: System.out.println(...) and System.out.print(...).
      • Data types: String literals.
    • Other variations
      • Display other greeting.
      • Display multiple lines of text.
      • May introduce backslash escaped characters such as "\n" and "\"".
  2. Input, output
  3. Input, numeric calculation, output
    • Understand
      • Read value, calc/convert - input, more numbers.
    • Example
    • Variations
      • Just about any conversion or calculation problem.
      • BMI - Body Mass Index. In metric, in English units.
  4. Strings
    • Understand
      • Read string, use string methods such as indexOf, substring, ... .
    • Example
    • Variations
      • To uppercase
      • Indexing - "First Last" to "Last, First"
      • Capitalize names "mickEy MaUs" to "Mickey Maus"
      • Convert mm/dd/yyyy date into yyyy-mm-dd style.
      • Find email address.

2. Conditional flow (if-else, switch)

3. Loops (while, for, do-while)

Methods