Final Exam Reference

This document is to be used for the prog10082 final exam. If you're looking for reference material from the first half of the course, scroll down or go to the mid term section directly.

REFRESH THIS PAGE !!!!!!

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

Modifiers

[ Top of Final Exam Reference | Mid Term Reference ]

Arrays

Array Syntax

Declare only

type[] arrayName;

Declare and Allocate Storage

type[] arrayName = new type[size];

Array size: length property

Access an element:

arrayName[index]

Coding with Arrays

for-each loop:

for (type var : array) { ... }

[ Top of Final Exam Reference | Mid Term Reference ]

String Processing

String Instance Methods

Character Static Methods

String Comparison

How strings are compared for inequality: ASCII values:

[ Top of Final Exam Reference | Mid Term Reference ]

Methods

Syntax:

modifier(s) returnType methodName(params if applicable) {
    ...
}

Calling statement:

methodName(arguments, if, any);
// or
qualifier.methodName(arguments, if, any);

Return stmt:

return thingToReturn;

[ Top of Final Exam Reference | Mid Term Reference ]

Object Oriented Programming: OOP

Syntax to construct an object:

Scanner in = new Scanner(System.in);

Other Methods:

public returnType getSomething()
public void setSomething(parameter)
public String toString()
public boolean equals(Object param)

IllegalArgumentException

[ Top of Final Exam Reference | Mid Term Reference ]

Material from First Half of Course

[ Final Exam Reference | Top of Mid Term Reference ]

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:

[ Final Exam Reference | Top of Mid Term Reference ]

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)

[ Final Exam Reference | Top of Mid Term Reference ]

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

[ Final Exam Reference | Top of Mid Term Reference ]

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

[ Final Exam Reference | Top of Mid Term Reference ]

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]

[ Final Exam Reference | Top of Mid Term Reference ]

Boolean Expressions

Relational/Conditional Operators:

Logical Operators:

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

[ Final Exam Reference | Top of Mid Term 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

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

[ Top of Final Exam Reference | Mid Term Reference ]

Iteration

Loop Syntax

while (condition) {

}
do {

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

}

Priming-Read/Continuing-Read Pattern

priming read
while (condition)
    ...
    continuing read

[ Final Exam Reference | Top of Mid Term Reference ]

Miscellaneous

Wrapper Class - Parse Methods

E.g. Integer.parseInt(string), Double.parseDouble(string), etc.