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 in case I made changes since you last viewed it. Changes will not be made during the exam.
[ Top of Final Exam Reference | Mid Term Reference ]
Declare only
type[] arrayName;
Declare and Allocate Storage
type[] arrayName = new type[size];
Array size: length
property
Access an element:
arrayName[index]
for-each loop:
for (type var : array) { ... }
[ Top of Final Exam Reference | Mid Term Reference ]
How strings are compared for inequality: ASCII values:
[ Top of Final Exam Reference | Mid Term Reference ]
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 ]
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
[ Final Exam Reference | Top of Mid Term Reference ]
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 ]
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 ]
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)
[ Final Exam Reference | Top of Mid Term Reference ]
Scanner: java.util
Scanner whatever = new Scanner(System.in);
Scanner methods:
System.out methods:
Conversion Codes and other Symbols:
Standard format for format specifier:
%[width].[digits][code]
[ Final Exam Reference | Top of Mid Term Reference ]
Relational/Conditional Operators:
Logical Operators:
Conditional Operator: ?:
(booleanExpression) ? valueIfTrue : valueIfFalse
[ Final Exam Reference | Top of Mid Term Reference ]
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
Steps to using RegEx classes:
Regex Syntax
[ Top of Final Exam Reference | Mid Term Reference ]
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 ]
E.g. Integer.parseInt(string), Double.parseDouble(string), etc.