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.
- 3.1.1 Blocks
- 3.1.2 The Basic While Loop
- 3.1.3 The Basic If Statement
- 3.1.4 Definite Assignment
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.
- 3.2.1 Pseudocode and Stepwise Refinement
- 3.2.2 The 3N+1 Problem
- 3.2.3 Coding, Testing, Debugging
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.
- 3.3.1 The while Statement
- 3.3.2 The do..while Statement
- 3.3.3 break and continue
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.
- 3.4.1 For Loops
- 3.4.2 Example: Counting Divisors
- 3.4.3 Nested for Loops
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.
- 3.5.1 The Dangling else Problem
- 3.5.2 Multiway Branching
- 3.5.3 If Statement Examples
- 3.5.4 The Empty Statement
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.
- 3.7.1 Exceptions
- 3.7.2 try..catch
- 3.7.3 Exceptions in TextIO
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.
- 3.8.1 Creating and Using Arrays
- 3.8.2 Arrays and For Loops
- 3.8.3 Random Access
- 3.8.4 Partially Full Arrays
- 3.8.5 Two-dimensional Arrays
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.
- 3.9.1 Drawing Shapes
- 3.9.2 Drawing in a Program
- 3.9.3 Animation
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.
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.