Computer Science 268: Introduction to Computer Programming (Java)

Study Guide

Unit 3

Read Chapter 3 of the textbook: Programming in the Small II: Control

This chapter continues our essential coverage of Java. It introduces additional building blocks of Java programs, including several control structures like blocks, loops and branches.

Section 3.1 Blocks, Loops, and Branches

This section discusses blocks of code, the while loop, the if statement and the definite assignment. Try the examples.

Read and review this section carefully.

Section 3.2 Algorithm Development

This section takes a break from essential Java elements to discuss critical design issues in writing good programs. The 3N+1 problem illustrates the topic well. Finally, the section discusses the iterative process of coding, testing and debugging.

Read and review this section carefully.

Section 3.3 The while and do..while Statements

This section continues the introduction and discussion of control structures, including the while statement, the do..while loop and, finally, break and continue statements. Again, try the examples.

Read and review this section carefully.

Section 3.4 The for Statement

This section continues the control structure discussion by introducing for loops and nested for loops. An extensive example is also included that illustrates the loops very well. Try the many good examples in the textbook.

Read and review this section carefully.

Section 3.5 The if Statement

This section revisits and extends the if statement that was introduced in subsection 3.1.3. Again, try the extensive examples that illustrate the concepts.

Read and review this section carefully.

Section 3.6 The switch Statement

This section introduces the switch statement, which is an elegant form of conditional branching. Concepts covered in this section include the basic switch statement, how the switch statement can be used to create menus, and other enhancements to the switch statement. Try the examples in this section.

Read and review this section carefully.

Section 3.7 Introduction to Exceptions and try..catch

This section introduces a new and advanced Java topic, the exception. Exceptions are a very powerful form of control structure, as they can be used to process error conditions that would otherwise cause your program to crash. Instead, the try–catch structure can be used to capture and contain possible error conditions when they occur.

Read and review this section carefully, except subsection 3.7.3 on TextIO, which is not covered in the course.

Section 3.8 Introduction to Arrays

This section introduces arrays. Arrays are excellent for storing multiple items of the same kind and represent one of the more fundamental data structures in Java. There are many object-oriented replacements for arrays in Java, but the lessons you learn about arrays serve as a foundation for all such structures. Read and review this section carefully.

Section 3.9 Introduction to GUI Programming

GUI programming is no longer an essential Java programming practice. Therefore, this section of the textbook is not covered in the course.

Programming Exercises

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 3 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.

Quiz

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.