Java 1 Study Guide
Essay by Stella • June 12, 2011 • Essay • 2,144 Words (9 Pages) • 2,020 Views
Chapter 2 Java Fundamentals
1. Common escape Sequences
a. \n (Newline), \t (Horizontal tab), \b (Backspace), \r (Return)
2. Identifiers - a programmer defined name that represents some element of a program
a. First character must be a letter, an underscore, or a dollar sign.
b. Identifiers cannot include spaces.
3. Java Key Words - core of the java language and show up blue when typing code.
4. Primitive Data Types (in order of precedence)
a. Byte
b. Short
c. Int
d. Long
e. Float
f. double
5. The boolean Data Type allows you to create variables that may hold one of two possible values: True or False.
6. The char data type is used to store characters (letters).
7. The final key word can be used in a variable declaration to make the variable a named constant. Named constants are initialized with a value, and that value cannot change during the execution of the program.
8. The String class allows you to create objects for holding strings. It also has various methods that allow you to work with strings.
9. A variables Scope is the part of the program that has access to the variable.
10. Reading Keyboard Input - Objects of the Scanner class can be used to read input from the keyboard. Example: import java.util.Scanner;
Chapter 3 Decision Structures
1. The if statement causes one or more statements to execute only when a Boolean expression is true.
2. The Boolean expression uses Relational Operators to test the if statement. (>,<,>=,<=,==, !=)
3. The if-else-if Statement is a chain that performs a series of tests until one of the tests is found to be true.
4. A nested if statement is an if statement in the conditionally executed code of another if statement.
5. Logical Operators connect two or more relational expressions into one or reverse the logic of an expression. Example: && operator connects two Boolean expressions requiring that they are both true to pass the testing statement.
6. The Conditional Operator can be used to create short expressions that work like if-else statements. Example: number = x > 100 ? 20 : 50 Read as if (x > 100) number = 20; else number = 50;
7. The DecimalFormat class can be used to format the appearance of floating-point numbers rounded to a specified number of decimal places. Example: import java.text.DecimalFormat;
Chapter 4 Loops and Files
1. The Increment and Decrement Operators ++ and - are operators that add and subtract one from their operands. Example: number = 1; number++
2. Increment and decrement operators can be written in postfix mode (number++) or prefix mode (++number). With prefix mode, the original value of number will never be tested because it will add 1 immediately.
3. The while Loop is part of a program that repeats. It has two important parts: (1) a Boolean expression that is tested for a true or false value, and (2) a statement or block of statements that is repeated as long as the expression is true.
4. The while Loop is a pretest loop, which means it tests its expression before each iteration.
5. Infinite Loops are loops that do not contain a way to terminate within themselves.
6. Using the while Loop for input validation. The while loop can be used to create input routines that repeat until acceptable data is entered.
7. The do-while Loop is a posttest loop, which means its Boolean expression is tested after each iteration. The do-while loop always performs at least one iteration.
8. The for Loop is ideal for performing a known number of iterations.
a. For (Initialization; Test; Update)
9. The for Loop is a pretest loop.
10. You can declare the variable in the for Loops Initialization Expression.
a. for (int number = 1; number <=10; number++)
b. for (Initialization; Test; Update)
11. You can use multiple statements in the Initialization and Update Expressions. Example: for (x = 1, y = 1; x <= 5; x++)
12. A running total is a sum of numbers that accumulates with each iteration of a loop. The variable used to keep the running total is called an accumulator. A sentinel is a value that signals when the end of a list of values has been reached.
13. The accumulator usually must be set to 0.0 for the program to run correctly.
14. A sentinel value is a special value chosen that must not be able to be mistaken as a member of the looping list, such as a -1 in a list of soccer game scores.
15. A loop that is inside another loop is called a Nested loop.
a. An inner loop goes through all of its iterations for each iteration of an outer loop (seconds within minutes)
b. Inner loops complete their iterations before outer loops do.
16. Deciding which Loop to use:
a. The while loop is a pretest loop. It is ideal in situations where you do not want the loop to iterate if the condition is false from the beginning. It is also ideal if you want to use a sentinel value to terminate the loop.
b. The do-while loop is a posttest loop. It is ideal in situations where you always want the loop to iterate at least once.
c. The for loop is a pretest loop that has built-in expressions for initializing, testing, and updating. These expressions make it very convenient to use a loop control variable as a counter. The for loop is ideal in situations where the exact number of iterations is known.
17. Introduction to
...
...