REFRESH THIS PAGE !!!!!!

Refresh this page in case I made changes since you last viewed it. Changes will not be made during the exam.

Mid Term Exam #2 Reference

This document is to be used for the prog10082 mid term exams.

[ Jump to Mid Term #1 Reference ]

Mid Term #2 Reference

Selections

if (expression) { 
    ... 
}
if (expression) {
    ....
} else {
    ....
}
if (expression) {
    ....
} else if (expression) {
    ....
} else if (expression) {
    ....
} else {
    ....
}
switch (expression) {
    case x:
    case y:
    case z:
    default:
}

Also: break; statement

[ MT #1 Ref | MT #2 Ref | Top of Page ]

Regular Expressions

Classes/Methods:

Steps to using RegEx classes:

  1. Create the Pattern object
  2. Create the Matcher object on the Pattern object for a specific String
  3. Execute one of the Matcher methods
  4. To use it again with a different string, reset the Matcher object

Regular Expression Syntax

Regex Syntax

[ MT #1 Ref | MT #2 Ref | Top of Page ]

Iteration

Loop Syntax

while (condition) {

}
do {

} while (condition);
for (initializer; condition; increment) {

}

Priming-Read/Continuing-Read Pattern

priming read
while (condition)
    ...
    continuing read

[ MT #1 Ref | MT #2 Ref | Top of Page ]

Mid Term #1 Reference

[ MT #2 Ref | Top of Page ]

Basic Stuff

class header: public class ...
main() header: public static void main(String[] args)

Semi-colons: at the end of executing statements, such as:

No semi-colon after:

IPO: Input / Processing / Output

Import statement:
import package.name.Class;

Escape sequences:

Categories of Errors:

Generate a Random Number:

between 1 and n:
(int)(Math.random() * n + 1)

between x and y:
(int)(Math.random() * (y - x + 1) + x)

[ MT #1 Ref | MT #2 Ref | Top of Page ]

Data Types

Reference types

Primitive Types:

Notations for floating point values:

Floating Point Number Storage (IEEE 754)

Data Type Description # bits for
Coefficient
# bits for
Exponent
# bits for
Sign
float Single-precision floating-point 23 8 1
double Double-Precision floating-point 52 11 1

[ MT #1 Ref | MT #2 Ref | Top of Page ]

Expressions and Math

Variable declaration:
type varname;

Variable declaration with initialization:
type varname = value;

Constants:

Assignment operator: =

Concatenation operator: +

String methods:

Arithmetic operators: + - / * %

Unary Arithmetic operators: ++ -- (both pre-fix and post-fix)

Augmented Assignment operators: += -= /= *= %=

Math Class methods

Casting operator: (type)

casting operations
Implicit vs. Explicit Casting

[ MT #1 Ref | MT #2 Ref | Top of Page ]

Input and Output

Getting Input

Scanner: java.util

Scanner whatever = new Scanner(System.in);

Scanner methods:

Displaying Output

System.out methods:

Formatting

Conversion Codes and other Symbols:

Standard format for format specifier:
%[width].[digits][code]

[ MT #1 Ref | MT #2 Ref | Top of Page ]

Boolean Expressions

Relational/Conditional Operators:

Logical Operators:

Conditional Operator: ?:
(booleanExpression) ? valueIfTrue : valueIfFalse

[ MT #1 Ref | MT #2 Ref | Top of Page ]