Exam 1 Topics
CS141: Introduction to Programming,
Fall 2011
General Comments and Recommendations
- The exam will cover Chapters 1-4 of the text.
- The exam will be 1 hour long. It will be closed book. Electronic devices, of any kind, will
not be allowed.
- It is strongly recommended that students:
- Re-read the text
- Do the self-check exercises in each chapter (answers are in the text)
- Review the reading quizzes
- Review the programming code-completion and programming exercises.
- Be able to do the loops described in this exercise.
Chapter 1: Introduction
- Java sytax for creating a class, e.g. see HelloPrinter on p. 13
- What is a statement?
- How is a block of code specified (i.e. with braces)?
- Name of java file must be same as the java class.
- Printing output using System.out.println()
- Programming Conventions (Style guide):
- files names begin with uppercase
- method (function) names begin with lowercase
- braces are on lines by themselves
- matching braces a lined up vertically with each other
- blocks of code are indented
- Compile vs Run-time Errors
Chapter 2: Fundamental Data Types
- Variables
- What is a variable?
- Data types - short, int, long, float, boolean, string, etc. What is the difference between float and double
or short and int?
- How is a variable declared? How many times can one declare a given variable?
- How is a variable initialized? How many times can one set the value of a given variable?
- How does the assignment statement work?
- Java syntax for arithmetic.
- Precedence of arithmetic operations.
- Integer division and remainder (mod function)
- Casting, e.g. forcing a float into an int
- Strings
- String methods (e.g. length, charAt, substring) and sytax for calling them,
StringName.methodName(inputs_to_method). See p. 65-66
- String concatentation and escape sequences
- Math methods (e.g. min, max, pow, sqrt)
Chapter 3: Decisions
- Boolean variables and values.
- What is a conditional expression?
- Comparisons: Relational operators, e.g. <, >, <=, >=, ==, !=
- Beware: relational operators are binary. For example, (2 < x < 5) is not a legal java expression.
- Beware: the == operator should not be used with Strings
- if statements, if-else statements (p. 80)
- Multiway if-else
- Nested if, if-else statements - line up brackets so the structure is clear!
- Beware of where you put semicolons!
- Switch statement
- Lexicographic ordering of Strings using the compareTo() method.
- Combining boolean expressions with AND (&&), OR (||), NOT (!)
Chapter 4: Loops
- Components of a loop
- Identify the loop variable (or whatever is controlling the loop)
- Controlling the loop - initializing the loop, loop condition, loop update
- What is the loop body?
- Types of loops:
- while loop
- for-loop
- do-while loop
- When is each type of loop used?
- What is a sentinel?
- What does it mean to trace or unravel a loop?
- Common Uses of Loops:
- Entering a sequence of values.
- Counting the number of items entered.
- Accumulating (e.g. summing) values
- Finding certain values (e.g. max or min)
- Prompting for correct type of input from user
- loop exercise