[ First Section | Previous Chapter | Next Chapter | Main Index ]

### Chapter 8

## Correctness, Robustness, Efficiency

In previous chapters, we have covered programming fundamentals. The chapters that follow this one will cover more advanced aspects of programming. The ideas that are presented will generally be more complex and the programs that use them a little more complicated. This relatively short chapter is a kind of turning point in which we look at the problem of getting such complex programs right.

Computer programs that fail are much too common. Programs are fragile. A tiny error can cause a program to misbehave or crash. Most of us are familiar with this from our own experience with computers. And we've all heard stories about software glitches that cause spacecraft to crash, web sites to go offline, telephone service to fail, and, in a few cases, people to die.

Programs don't have to be as bad as they are. It might well be impossible to guarantee that programs are problem-free, but careful programming and well-designed programming tools can help keep the problems to a minimum. This chapter will look at issues of correctness and robustness of programs. Section 8.2 discusses how you can think about and analyze programs to make the programs that you write more likely to be correct—possibly even provably correct.

Section 8.3 looks more closely at exceptions and the try..catch statement, and Section 8.4 introduces assertions, another of the tools that Java provides as an aid in writing correct programs.

In Section 8.5, we look at another issue that is important for programs in the real world: efficiency. Even a completely correct program is not very useful if it takes an unreasonable amount of time to run. The last section of this chapter introduces techniques for analyzing the run time efficiency of algorithms.

Some of the topics in this chapter are the topics of advanced courses in computer science, and only a brief overview can be given here. But what you do learn here will be useful in the rest of the book.

### Contents of Chapter 8:

- Section 1: Introduction to Correctness and Robustness
- Section 2: Writing Correct Programs
- Section 3: Exceptions and try..catch
- Section 4: Assertions and Annotations
- Section 5: Analysis of Algorithms
- Programming Exercises
- Quiz on This Chapter

[ First Section | Previous Chapter | Next Chapter | Main Index ]