AP CSA Full Review of Units 1-10 (2025)

Unit 1: Primitive Types

Note: variable long doesn’t show up in the exam

Casting

Unit 2: Using Objects

What are Objects and Classes

String Methods

Strings are not primitive types, but are composed of characters (char), which is a primitive type.

  1. Essential Methods for the AP Exam

    • int length()int length(): Returns the total number of characters in the string.

    • String substring(int from, int to)String substring(int fromint to): Returns a new string starting at index from and ending just before index to (index to is exclusive). Length of result is (to−from)(tofrom).

    • String substring(int from)String substring(int from): Returns a new string starting at index from and going to the end of the string.

    • int indexOf(String str)int indexOf(String str): Returns the index of the first occurrence of str within the string; returns −1−1 if not found.

    • boolean equals(String other)boolean equals(String other): Checks if two strings contain the same characters in the same order.

    • int compareTo(String other)int compareTo(String other): Compares strings lexicographically (alphabetically). Returns 00 if they are equal, a negative integer if the string is less than other, and a positive integer if it is greater.

  2. Important Rules to Know

    • Indexing: Java strings use zero-based indexing. The first character is at index 00, and the last character is at index length()−1length()−1.

    • Bounds: Accessing an index less than 00 or greater than or equal to length()length() will throw a StringIndexOutOfBoundsException.

    • Concatenation: You can use the ++ operator to join strings or a string and a primitive (the primitive will be converted to a string).

Wrapper Class

Math Class

The Math class provides static methods for common mathematical calculations. Since these are static, you call them directly using the class name.

  • static int abs(int x)static int abs(int x) / static double abs(double x)static double abs(double x): Returns the absolute value of a number (e.g., Math.abs(−5)Math.abs(−5) is 55).

  • static double pow(double base, double exponent)static double pow(double basedouble exponent): Raises a base to a specific exponent. Crucially, this always returns a doubledouble.

  • static double random()static double random(): Returns a random doubledouble in the range [0.0,1.0)[0.0,1.0). To generate a random integer between minmin and maxmax, use: (int)(Math.random()∗(max−min+1))+min(int)(Math.random()∗(maxmin+1))+min.

  • static double sqrt(double x)static double sqrt(double x): Returns the positive square root of a double value.

  • static int max(int a, int b)static int max(int aint b) / static int min(int a, int b)static int min(int aint b): Returns the larger or smaller of two values. Example: if a=10a=10

Unit 3: Boolean Expressions and if Statements

If Statements

Unit 5: Writing Classes

Constructors

Types of Methods

Methods

This Keyword

Unit 6: Array

  • The size of arrays cannot be changed, however values can be updated like this:

            array[i] = value

  • You can only have 1 type in an array

  • : means in

    customer in customers

Unit 7: ArrayList

  • ArrayLists don’t have a specified size

  • You can have multiple types in an ArrayList if the type isn’t specified

Methods

Unit 9: Inheritance