Units 1-2 introduce Java fundamentals — primitive data types, variables, operators, and the concept of objects and methods. These form the building blocks for all subsequent AP CS A topics.
int (whole numbers), double (decimal), boolean (true/false). Declaration: int age = 17; Arithmetic: +, -, *, /, % (modulo). Integer division truncates: 7/2 = 3. Casting: (double) 7/2 = 3.5. Compound assignment: +=, -=, *=, /=, %=. Increment/decrement: ++, --. Overflow: exceeding int range wraps around.
Objects: instances of classes, created with new keyword. String: reference type, immutable. Methods: .length(), .substring(begin, end), .indexOf(str), .equals(other), .compareTo(other). Concatenation: + operator (auto-converts primitives to strings). Escape sequences: \\n, \\t, \\\\, \\". Math class: Math.abs(), Math.pow(), Math.sqrt(), Math.random() (returns [0.0, 1.0)). Integer.MAX_VALUE, Integer.MIN_VALUE for range limits.
In Java, when both operands of the division operator are integers, integer division is performed — the result is truncated (not rounded) to the nearest integer toward zero. So 7/2 = 3 (not 3.5). To get decimal division, at least one operand must be a double: 7.0/2 = 3.5, or (double)7/2 = 3.5. This is a very common source of bugs and is frequently tested on the AP exam. Note: -7/2 = -3 (truncates toward zero, not negative infinity).
Book a Trial + Diagnostic session. Get a personalized Learning Path with clear milestones, tutor match, and a plan recommendation — all within 24 hours.
Book Trial + Diagnostic →