Computer Science 268: Introduction to Computer Programming (Java)
Study Guide
Unit 8
Read Chapter 8 of the textbook: Correctness, Robustness, Efficiency
This chapter discusses programming, in general, proper design, and ways of ensuring that programs do what they were designed to do. Programs may be designed “correctly”—meaning, they appear to achieve the design goals—but if they were designed poorly, they may actually output “incorrectly.” That is, they may compile and run, but they may output erroneous or unexpected results, especially in cases where input is not clearly defined. Robustness refers to how well a program can accommodate unexpected actions (i.e., “bad input data”) and respond gracefully. Efficiency refers to how well a program uses its computational resources.
Section 8.1 Introduction to Correctness and Robustness
This section introduces program correctness and robustness, and it discusses how they can affect program performance.
Read and review this section carefully.
- 8.1.1 Horror Stories
- 8.1.2 Java to the Rescue
- 8.1.3 Problems Remain in Java
Section 8.2 Writing Correct Programs
This section discusses ways to determine whether a program is correct, and how to effectively create correct programs.
Read and review this section carefully.
- 8.2.1 Provably Correct Programs
- 8.2.2 Preconditions and Postconditions
- 8.2.3 Invariants
- 8.2.4 Robust Handling of Input
Section 8.3 Exceptions and try..catch
This section discusses exceptions as a mechanism to gracefully handle unexpected events during program execution.
Read and review this section carefully.
- 8.3.1 Exceptions and Exception Classes
- 8.3.2 The try Statement
- 8.3.3 Throwing Exceptions
- 8.3.4 Mandatory Exception Handling
- 8.3.5 Programming with Exceptions
Section 8.4 Assertions and Annotations
The section is about advanced Java programming. Therefore, section 8.4 of the textbook is not covered in the course.
- 8.4.1 Assertions
- 8.4.2 Annotations
Section 8.5 Analysis of Algorithms
This section presents an introduction to the more advanced topic of algorithm analysis. A more detailed discussion is beyond the scope of this course. In fact, algorithm analysis comprises an entire course that Athabasca University offers, called COMP 272; you may wish to take it after you have completed COMP 268. This is an essential section to be read and reviewed.
It is a good practice to attempt the programming exercises in the textbook, to put the topics you have learned into concrete Java code. This, in turn, allows you to reflect on the material you have read. Skip any exercises relating to topics in Chapter 8 that are not covered in the course.
Resist the temptation to download the programming exercises from the textbook and simply run them. The greatest benefit in learning to program in a new language occurs when you type all the example code yourself.
Typing the code, even for simple examples, engages your brain in the process of writing code, compiling code, running code, and diagnosing and resolving problems that may arise. It is the latter skill—problem solving—that can become the most powerful tool in learning to program.
It is a good practice to review the chapter quizzes in the textbook, as the questions allow you to reflect on the material you have read.