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 #1 Reference

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

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)

[ 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

[ 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

[ 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]

[ Top of Page ]

Boolean Expressions

Relational/Conditional Operators:

Logical Operators:

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

[ Top of Page ]