AP exam review verified for 2027

AP Computer Science A Unit 1 Review: Using Objects and Methods

Review AP CSA Unit 1 to build your foundation in Java: variables, data types, arithmetic expressions, object creation, and calling methods from built-in classes like Math and String. This unit carries 15-25% of the exam weight and appears in nearly every multiple-choice question that asks you to trace code.

Use the topic guides, key terms, and practice questions available for this unit to work through every concept before exam day.

What is AP Computer Science A unit 1?

Unit 1 covers the core mechanics of Java that every other unit builds on. You start with how algorithms work and how Java turns source code into a running program, then move through variables, expressions, assignment, and casting. The second half of the unit shifts to object-oriented thinking: what a class is, how to create objects with constructors, and how to call instance and class methods. The Math and String classes give you concrete practice with all of these ideas.

Unit 1 teaches you to write and trace basic Java programs using variables, arithmetic expressions, object creation, and method calls. The key skill is predicting exactly what value a variable holds or what output a program produces after each statement executes.

Primitive types and arithmetic

Java has three primitive types you need for this course: int, double, and boolean. Arithmetic follows operator precedence (*, /, % before +/-), and dividing two ints drops the decimal. Casting with (int) or (double) lets you convert between types, but casting a double to an int truncates, it does not round.

Classes, objects, and constructors

A class is a blueprint; an object is a specific instance created from that blueprint. You create objects with the new keyword and a constructor call, like new String("hello"). A reference variable stores the memory address of the object, not the object itself. Calling a method on a null reference causes a NullPointerException.

Math and String methods

Math class methods (Math.abs, Math.pow, Math.sqrt, Math.random) are static, so you call them on the class name. String methods (length, substring, indexOf, equals, compareTo) are instance methods called on a String object. Strings are immutable: methods return new String objects and never change the original.

Everything in Java is either a primitive value or an object reference

The single most important distinction in Unit 1 is the difference between primitive types (int, double, boolean) and reference types (String, Math, any class). Primitives store their value directly in the variable. Reference variables store a pointer to an object in memory. This distinction explains casting behavior, NullPointerException, String immutability, and how arguments are passed to methods using call by value. Keep this mental model active as you trace every code segment in the unit.

AP Computer Science A unit 1 topics

1.1

Introduction to Algorithms, Programming, and Compilers

Algorithms are step-by-step processes where sequencing matters. Java code is compiled before it runs, and the compiler catches syntax errors. Logic errors and run-time errors require testing or execution to detect.

open guide
1.2

Variables and Data Types

Java variables have a declared type: int, double, or boolean for primitives, or a class name for reference types. A variable must be initialized before use. Reference variables hold a memory address, not the object itself.

open guide
1.3

Expressions and Output

System.out.print and System.out.println display output. Arithmetic follows operator precedence, and integer division truncates. The + operator concatenates strings when at least one operand is a String.

open guide
1.4

Assignment Statements and Input

The = operator evaluates the right-hand expression and stores the result in the left-hand variable. Types must be compatible. The Scanner class reads text input, but specific input code is not tested on the AP exam.

open guide
1.5

Casting and Range of Variables

Use (int) to truncate a double to an int, or (double) to widen an int. Integer overflow occurs when an int result exceeds Integer.MAX_VALUE. Round-off error occurs when a double cannot be stored exactly.

open guide
1.6

Compound Assignment Operators

Operators +=, -=, *=, /=, and %= combine arithmetic with assignment. x++ and x-- add or subtract 1 from a variable. Trace the variable value after each compound assignment statement.

open guide
1.7

Application Program Interface (API) and Libraries

Libraries are collections of classes. An API specification documents a class's attributes (data in variables) and behaviors (methods). You use a class by reading its API, not its source code.

open guide
1.8

Documentation with Comments

Java supports single-line (//), block (/* */), and Javadoc (/** */) comments. Comments are ignored by the compiler. Preconditions and postconditions document what a method requires and guarantees.

open guide
1.9

Method Signatures

A method signature is the method name plus its ordered parameter types. Arguments must match in number, order, and compatible type. Void methods return nothing; non-void methods return a value that must be stored or used.

open guide
1.10

Calling Class Methods

Static methods belong to the class, not an object. Call them with ClassName.methodName(args). The keyword static appears in the method header. Inside the defining class, the class name is optional.

open guide
1.11

Math Class

Math is in java.lang and needs no import. Its methods are all static: Math.abs, Math.pow, Math.sqrt, and Math.random. Use the scale-and-shift formula with Math.random() to generate random integers in a range.

open guide
1.12

Objects: Instances of Classes

A class is a blueprint; an object is a specific instance. A reference variable holds the memory address of an object. All Java classes are subclasses of the Object class.

open guide
1.13

Object Creation and Storage (Instantiation)

Create objects with new ClassName(args). The constructor name matches the class name and can be overloaded. Arguments are passed by value. A reference variable holds the object's address or null.

open guide
1.14

Calling Instance Methods

Call instance methods with objectReference.methodName(args). Each object uses its own data. Calling a method on a null reference throws NullPointerException at runtime.

open guide
1.15

String Manipulation

String is an immutable reference type. Use length(), substring(), indexOf(), equals(), and compareTo() from the Java Quick Reference. Indices run from 0 to length()-1. Use equals(), not ==, to compare String content.

open guide
practice snapshot

Hardest AP Computer A unit 1 topics

This snapshot uses Fiveable practice activity to show where students tend to miss questions and which review moves are worth prioritizing first.

66%average MCQ accuracy

Across 8.5k multiple-choice practice attempts for this unit.

8.5kMCQ attempts

Practice activity included in this snapshot.

Unit 1 review notes

1.1

Algorithms, compilation, and error types

An algorithm is a step-by-step process where sequencing matters: each step runs one at a time in order. Java source code is written in a text editor or IDE, then a compiler translates it into a form the computer can run. The compiler catches some errors before the program runs, but not all of them.

  • Syntax error: A violation of Java language rules caught by the compiler before the program runs; for example, a missing semicolon or mismatched brace.
  • Logic error: A mistake in the algorithm that causes wrong output; the program compiles and runs but produces an unexpected result. Found only through testing.
  • Run-time error: An error that occurs during execution and typically terminates the program abnormally; for example, dividing an int by zero.
  • Exception: A specific type of run-time error, such as ArithmeticException or NullPointerException, that interrupts normal program flow.
  • IDE: An integrated development environment that provides tools to write, compile, and run code in one place.
Given a short Java program with a missing semicolon, an incorrect formula, and a divide-by-zero, can you identify which error is a syntax error, which is a logic error, and which is a run-time error?
Error typeWhen detectedExample
Syntax errorCompile timeMissing semicolon, unclosed brace
Logic errorTesting (not compiler)Wrong formula produces bad output
Run-time errorDuring executionInteger divide by zero
ExceptionDuring executionNullPointerException, ArithmeticException
1.2

Variables and primitive data types

A variable is a named storage location whose value can change while the program runs. Every variable has a declared type. The three primitive types in AP CSA are int (whole numbers), double (real numbers), and boolean (true or false). Reference types, like String, store a pointer to an object rather than the value itself. You must initialize a variable before using it in an expression.

  • int: Stores whole-number values; arithmetic between two ints produces an int result.
  • double: Stores real-number values; any arithmetic involving at least one double produces a double result.
  • boolean: Stores only true or false; used in conditions and logical expressions.
  • Reference type: A type whose variable holds a memory address pointing to an object, not the object's value directly. String is the main reference type in Unit 1.
  • Variable declaration: Syntax: type variableName; or type variableName = value; The variable must be initialized before use.
Write a declaration for each of the three primitive types and one reference type. Then identify which type you would use to store a student's GPA, a count of items, and a flag for whether a user is logged in.
TypeCategoryExample values
intPrimitive0, -5, 1000
doublePrimitive3.14, -0.5, 2.0
booleanPrimitivetrue, false
StringReference"hello", "AP CSA"
1.3

Expressions, output, and operator precedence

System.out.print displays output and keeps the cursor on the same line; System.out.println moves to a new line after printing. Arithmetic expressions follow precedence rules: *, /, and % evaluate before + and -. When both operands are int, division truncates the decimal. Mixing an int and a double promotes the result to double. The + operator concatenates strings when at least one operand is a String.

  • System.out.println vs System.out.print: println adds a newline after output; print does not. Both accept strings, numbers, and expressions.
  • Integer division: 7 / 2 evaluates to 3, not 3.5, because both operands are int. The fractional part is discarded.
  • Remainder operator %: 7 % 2 evaluates to 1. Useful for checking divisibility or cycling through a range.
  • Operator precedence: *, /, % are evaluated before + and -. Use parentheses to override the default order.
  • String concatenation: "Score: " + 95 produces "Score: 95". A primitive concatenated with a String is implicitly converted to a String.
Predict the output of: System.out.println(7 / 2 + " " + 7 % 2 + " " + 7.0 / 2);
1.4

Assignment, casting, and variable ranges

The assignment operator = evaluates the right-hand expression first, then stores the result in the left-hand variable. The value must be a compatible type. Casting with (int) or (double) converts between primitive types explicitly. Casting a double to an int truncates toward zero. Widening from int to double happens automatically. Integer overflow occurs when an int expression exceeds Integer.MAX_VALUE or goes below Integer.MIN_VALUE, producing an unexpected in-range result. Round-off error occurs when a double value cannot be represented exactly in memory.

  • Assignment operator =: Stores the value of the right-hand expression into the left-hand variable. Not equality comparison.
  • (int) cast: Truncates the decimal part of a double: (int) 3.9 produces 3, not 4.
  • Widening conversion: An int is automatically promoted to double when needed, such as in mixed arithmetic or assignment to a double variable.
  • Integer overflow: When an int result exceeds Integer.MAX_VALUE (about 2.1 billion), it wraps around to a negative value instead of throwing an error.
  • Round-off error: A double cannot always represent a value exactly, so the stored result may differ slightly from the mathematical result.
What does (int)(7.9) evaluate to? What happens if you add 1 to Integer.MAX_VALUE? Explain both results.
1.6

Compound assignment operators

Compound assignment operators combine an arithmetic operation with assignment in one step. x += 5 is equivalent to x = x + 5. The post-increment operator x++ adds 1 to x and stores the result back in x. These operators appear frequently in loop counters and running totals, so tracing the exact value of a variable after each statement is the key skill.

  • +=, -=, *=, /=, %=: Each performs the indicated operation on the current variable value and the right-hand operand, then stores the result back in the variable.
  • x++ (post-increment): Adds 1 to x and stores the new value in x. In AP CSA, x++ is used as a standalone statement, not inside a larger expression.
  • x-- (post-decrement): Subtracts 1 from x and stores the new value in x.
If x = 10, what is x after x *= 3; then x %= 7;? Trace each step.
1.7

APIs, libraries, and documentation

A library is a collection of classes grouped into packages. An API specification tells you how to use those classes without needing to read their source code. Attributes are the data a class stores in variables; behaviors are what the class can do, defined by methods. Comments document code for human readers but are ignored by the compiler. Preconditions state what must be true before a method runs; postconditions state what is guaranteed to be true after it runs.

  • API: Application programming interface: documentation that describes a class's attributes and behaviors so you can use it without knowing its internal implementation.
  • Single-line comment //: Documents one line; ignored by the compiler.
  • Block comment /* */: Documents multiple lines; ignored by the compiler.
  • Javadoc comment /** */: Used to generate API documentation; appears before class and method headers.
  • Precondition / postcondition: A precondition must be true before a method is called. A postcondition describes what is guaranteed to be true after the method returns.
A method has the precondition that its int parameter must be positive. Who is responsible for ensuring this condition is met before the method is called?
1.9

Method signatures, calling methods, and static methods

A method signature consists of the method name and its ordered list of parameter types. Arguments passed in a method call must match the parameter list in number, order, and compatible type. Void methods do not return a value and cannot be used in an expression. Non-void methods return a value that must be stored or used. Static (class) methods belong to the class, not to any object, and are called using the class name and dot operator, like Math.sqrt(16).

  • Method signature: The method name plus the ordered list of parameter types. Return type is not part of the signature.
  • Call by value: Arguments are copied into parameters. Changing a parameter inside a method does not affect the original variable.
  • Void method: Returns no value; called as a standalone statement. Example: System.out.println("hi");
  • Non-void method: Returns a value of the declared return type; the result must be stored or used in an expression.
  • Static method: Belongs to the class, not an instance. Called as ClassName.methodName(args). The keyword static appears in the method header.
  • Method overloading: Multiple methods share the same name but have different parameter lists. The compiler selects the correct version based on the arguments.
Math.abs is overloaded with versions for int and double. If you call Math.abs(-3), which version runs and what does it return?
Method typeCalled onSyntax exampleReturns value?
Static (class) methodClass nameMath.sqrt(9.0)Yes (double)
Instance methodObject referencestr.length()Yes (int)
Void methodClass or objectSystem.out.println(x)No
1.11

Math class methods

The Math class is in java.lang, so no import is needed. All Math methods are static. The four methods on the Java Quick Reference are Math.abs (int and double versions), Math.pow(base, exponent), Math.sqrt(x), and Math.random(). Math.random() returns a double in [0.0, 1.0). To generate a random int in a range, use the scale-and-shift pattern: (int)(Math.random() * (max - min + 1)) + min for an inclusive range.

  • Math.abs(x): Returns the absolute value of x. Works for both int and double arguments.
  • Math.pow(base, exp): Returns base raised to the power exp as a double. Math.pow(2, 10) returns 1024.0.
  • Math.sqrt(x): Returns the nonnegative square root of x as a double.
  • Math.random(): Returns a random double d where 0.0 <= d < 1.0. Cast and scale to get integers in a specific range.
  • Scale-and-shift formula: (int)(Math.random() * (max - min + 1)) + min generates a random int from min to max inclusive.
Write an expression that generates a random integer from 1 to 6 inclusive, simulating a die roll.
1.12

Classes, objects, and constructors

A class is the blueprint that defines attributes (instance variables) and behaviors (methods). An object is a specific instance of a class created at runtime. You create an object with the new keyword followed by a constructor call. The constructor's name matches the class name, and constructors can be overloaded. A reference variable stores the memory address of the object. If a reference variable holds null, calling any method on it causes a NullPointerException.

  • Class vs object: A class defines the structure; an object is a specific instance with its own attribute values created from that class.
  • Constructor: A special method with the same name as the class, called with new to initialize a new object's attributes.
  • Constructor overloading: Multiple constructors with different parameter lists allow objects to be created with different initial values.
  • Object reference: A reference variable holds the memory address of an object, not the object itself. Two variables can reference the same object.
  • null: A special value indicating a reference variable does not point to any object. Calling a method on null causes NullPointerException.
A class Student has two constructors: Student(String name) and Student(String name, int grade). Which constructor runs for new Student("Alex")? What does the reference variable store after this call?
1.14

Calling instance methods

Instance methods are called on a specific object using the dot operator: objectReference.methodName(arguments). Each object runs the method using its own instance variables, so two objects of the same class can return different results from the same method call. A void instance method is called as a standalone statement. A non-void instance method returns a value that must be stored or used. Always verify the reference is not null before calling a method on it.

  • Dot operator: Used between an object reference and a method name to call an instance method: myObject.doSomething().
  • NullPointerException: Thrown at runtime when you call an instance method on a reference variable that holds null.
  • Instance method vs static method: Instance methods require an object; static methods are called on the class name. Both use the dot operator but with different left-hand sides.
If String s = null; what happens when you call s.length()? Name the error and explain why it occurs.
1.15

String objects and String methods

A String is an immutable reference type in java.lang. You can create one with a string literal or with new String(). Because Strings are immutable, methods like substring and toUpperCase return new String objects; they do not modify the original. String indices run from 0 to length() - 1. The five String methods on the Java Quick Reference are length(), substring(from, to), substring(from), indexOf(str), equals(other), and compareTo(other).

  • String immutability: Once created, a String's characters cannot change. Methods return new String objects rather than modifying the original.
  • length(): Returns the number of characters in the String as an int. "hello".length() returns 5.
  • substring(from, to): Returns the substring from index from up to but not including index to. "hello".substring(1, 3) returns "el".
  • indexOf(str): Returns the index of the first occurrence of str, or -1 if not found.
  • equals(other): Returns true if the two Strings contain the same sequence of characters. Use equals, not ==, to compare String content.
  • compareTo(other): Returns a negative int if this String comes before other lexicographically, 0 if equal, positive if after.
For String s = "computer"; what does s.substring(0, 4) return? What does s.indexOf("put") return? What does s.length() return?

Practice AP Computer Science A unit 1 questions

Try AP-style multiple-choice questions and written prompts after you review the notes.

Example AP-style MCQs

open all practice
MCQ

AP-style practice question

Question

A robotics team is testing a navigation algorithm using unique Trial IDs. Data set 1 contains the Trial ID and the initialization code text. Data set 2 contains the Trial ID and the NullPointerException logs. Data set 3 contains the Trial ID and the actual final robot coordinates. Data set 4 contains the Trial ID and the expected final robot coordinates. A developer wants to determine which specific initialization code causes the program to crash during execution because an object was never created. Which two data sets must be combined?

Data sets 1 and 2, to link the specific initialization code to the run-time errors encountered.

Data sets 1 and 4, to link the specific initialization code to the expected logic output values.

Data sets 2 and 3, to link the actual final coordinates to the run-time errors encountered.

Data sets 3 and 4, to link the actual final coordinates to the expected logic output values.

MCQ

AP-style practice question

Question

Consider the following method that is intended to read positive integers from a Scanner and return their sum. The input ends when a negative integer or zero is read.

</>Java
public int sumPositive(Scanner in) {
    int sum = 0;
    int num = in.nextInt();
    while (num > 0) {
        /* missing code */
    }
    return sum;
}

Which of the following can replace /* missing code */ so that the method works as intended?

sum += num; num = in.nextInt();

num = in.nextInt(); sum += num;

sum += num; sum = in.nextInt();

num += sum; num = in.nextInt();

Example FRQs

open all FRQs
FRQ

Event sequence tracking and keyword counting

1. This question involves the SimulationLog class, which tracks a sequence of events in a system simulation. The SimulationLog class uses a helper method, getNextEvent, to determine the sequence of events. You will write a constructor and a method in the SimulationLog class.

</>Java
public class SimulationLog
{
    /** The string containing all events, separated by " -> " */
    private String log; // To be initialized in part (a)

    /** The number of events currently in the log */
    private int numEvents; // To be initialized in part (a)

    /**
     * Initializes the log with the starting event and appends subsequent events
     * obtained by calling getNextEvent until a null event is returned.
     * Updates log and numEvents as described in part (a).
     * Precondition: startEvent is a non-empty string.
     */
    public SimulationLog(String startEvent)
    { /* to be implemented in part (a) */ }

    /**
     * Returns the next event based on the previous event.
     * Returns null if there are no more events.
     * Precondition: prevEvent is a non-empty string.
     */
    public String getNextEvent(String prevEvent)
    { /* implementation not shown */ }

    /**
     * Returns the number of times the keyword appears in the log.
     * Occurrences of keyword are non-overlapping.
     * Precondition: keyword is a non-empty string.
     */
    public int countKeyword(String keyword)
    { /* to be implemented in part (b) */ }

    /* There may be instance variables, constructors, and methods that are not shown. */
}
a.

Write the SimulationLog constructor, which initializes the instance variables log and numEvents. The constructor starts the log with the parameter startEvent and sets numEvents to 1. It then repeatedly calls the helper method getNextEvent to obtain the next event in the sequence. The argument passed to getNextEvent is the event most recently added to the log. If getNextEvent returns a non-null string, the constructor appends the delimiter " -> " followed by the new event to log and increments numEvents. The process stops when getNextEvent returns null.

The helper method getNextEvent returns the next event string based on the current event. Consecutive calls to getNextEvent are guaranteed to eventually return null, ensuring the constructor terminates.

Example 1

Consider the following calls to getNextEvent made within the constructor. The return value of each call is used as the argument for the next call.
Method CallReturn Value
getNextEvent("boot")"check"
getNextEvent("check")"run"
getNextEvent("run")"end"
getNextEvent("end")null
Based on these return values, a call to new SimulationLog("boot") should set the instance variable log to "boot -> check -> run -> end" and set numEvents to 4.

Example 2

Consider the following calls to getNextEvent:
Method CallReturn Value
getNextEvent("alert")"notify"
getNextEvent("notify")null
Based on these return values, a call to new SimulationLog("alert") should set the instance variable log to "alert -> notify" and set numEvents to 2.
Complete the SimulationLog constructor.
/**
 * Initializes the log with the starting event and appends subsequent events
 * obtained by calling getNextEvent until a null event is returned.
 * Updates log and numEvents as described in part (a).
 * Precondition: startEvent is a non-empty string.
 */
public SimulationLog(String startEvent)
b.

Write the countKeyword method, which returns the number of times the parameter keyword appears in the instance variable log. The method counts only non-overlapping occurrences. For example, if log contains "anana" and keyword is "ana", the method should count 1 occurrence (the first "ana"), not 2.

Example 1

Assume the instance variable log contains "boot -> check -> run -> end".
Method CallReturn Value
countKeyword("check")1
countKeyword("error")0
The keyword "check" appears once. The keyword "error" does not appear.

Example 2

Assume the instance variable log contains "test -> retest -> test -> done".
Method CallReturn Value
countKeyword("test")3
countKeyword("retest")1
The keyword "test" appears in "test", "retest", and "test". Note that "retest" contains "test".
Complete the countKeyword method.
/**
 * Returns the number of times the keyword appears in the log.
 * Occurrences of keyword are non-overlapping.
 * Precondition: keyword is a non-empty string.
 */
public int countKeyword(String keyword)

Key terms

TermDefinition
compilerA program that translates Java source code into a runnable form and detects syntax errors before the program executes.
logic errorA mistake in the algorithm that causes incorrect output; the program compiles and runs but produces an unexpected result, detected only through testing.
arithmetic expressionA combination of numeric values, variables, and operators (+, -, *, /, %) that evaluates to a single int or double result following operator precedence rules.
integer divisionDivision of two int values that discards the fractional part: 7 / 2 evaluates to 3, not 3.5.
remainder operatorThe % operator returns the remainder after division: 7 % 3 evaluates to 1. Useful for divisibility checks and cycling through ranges.
cast operatorSyntax of the form (int) or (double) that explicitly converts a value to the specified primitive type. Casting a double to int truncates toward zero.
round-off errorA loss of precision when a double value cannot be stored exactly in memory, causing the result to be rounded to the nearest representable value.
object instantiationCreating a new object from a class using the new keyword and a constructor call, for example new String("hello") or new Scanner(System.in).
object referenceThe value stored in a reference-type variable: a memory address pointing to an object on the heap, not the object's data directly.
null referenceA reference variable that does not point to any object. Calling a method on a null reference causes a NullPointerException at runtime.
call by valueThe argument-passing mechanism in Java: a copy of the argument's value is passed to the parameter. Changes to the parameter inside the method do not affect the original variable.
instance methodA method that belongs to an object and is called using the dot operator on an object reference: objectRef.methodName(args).
Math.random()A static Math class method that returns a random double d where 0.0 <= d < 1.0. Scale and cast to produce random integers in a specific range.
string literalA sequence of characters enclosed in double quotes, such as "hello", used to create a String object directly in code.
operator precedenceThe rules that determine evaluation order in a compound expression: *, /, and % are evaluated before + and -. Parentheses override the default order.

Common unit 1 mistakes

Confusing integer division with decimal division

When both operands are int, Java discards the decimal: 5 / 2 is 2, not 2.5. To get 2.5, at least one operand must be a double: 5.0 / 2 or (double) 5 / 2. This mistake causes silent wrong answers in arithmetic traces.

Using == to compare String content

The == operator checks whether two reference variables point to the same object in memory, not whether they contain the same characters. Always use .equals() to compare String values: str1.equals(str2).

Expecting (int) to round instead of truncate

(int) 3.9 produces 3, not 4. Casting toward zero always drops the decimal. To round to the nearest integer, use (int)(x + 0.5) for nonnegative values.

Calling an instance method on a null reference

If a reference variable has not been assigned an object (or was assigned null), calling any method on it throws NullPointerException at runtime. Always confirm an object was created with new before calling its methods.

Off-by-one errors in String indexing

String indices start at 0, not 1. The last valid index is length() - 1. In substring(from, to), the character at index to is not included. Accessing an out-of-range index throws StringIndexOutOfBoundsException.

How this unit shows up on the AP exam

Code tracing on multiple-choice questions

A large portion of AP CSA multiple-choice questions ask you to trace a short code segment and identify the exact output or the value stored in a variable. Unit 1 skills, including integer division, casting, compound assignment, and String method calls, appear directly in these traces. Practice evaluating expressions step by step without a compiler.

Reading and using method signatures

The AP CSA exam frequently presents a class or method you have not seen before and asks you to call it correctly or predict its return value. Unit 1 teaches you to read a method signature, match arguments to parameters by type and order, and determine whether the return value must be stored. This skill applies to every class you encounter on the exam.

Writing code that creates and uses objects

Free-response questions often require you to write code that instantiates objects, calls instance methods, and uses return values in expressions. Unit 1 establishes the syntax for new, the dot operator, and method calls. Errors like calling a method on null or using == instead of equals on Strings are common points of deduction on written-response tasks.

Final unit 1 review checklist

  • Identify and classify error typesGiven a Java program, distinguish syntax errors (caught by compiler), logic errors (wrong output), and run-time errors or exceptions (crash during execution). Know an example of each.
  • Declare variables and choose the right typeWrite correct declarations for int, double, boolean, and String. Explain why you would choose double over int for a GPA and int over double to avoid rounding errors in a counter.
  • Trace arithmetic expressions including integer division and castingEvaluate expressions like (int)(7.9), 7 / 2, 7 % 3, and 7.0 / 2 without a compiler. Apply operator precedence and identify when a result is int versus double.
  • Trace compound assignment operatorsGiven a sequence of statements using +=, *=, %=, x++, and x--, determine the exact value stored in each variable after every statement.
  • Read a method signature and write a correct callGiven a method header like static double pow(double base, double exponent), write a valid call, identify the return type, and explain what happens to the return value if it is not stored.
  • Create objects and call instance methodsWrite code to instantiate an object using new, call an instance method with the dot operator, and explain what NullPointerException is and when it occurs.
  • Use Math and String methods from the Java Quick ReferenceWrite expressions using Math.abs, Math.pow, Math.sqrt, and Math.random. Trace String method calls for length(), substring(from, to), indexOf(), equals(), and compareTo() on a given String.

How to study unit 1

Step 1: Algorithms, compilation, and error types (Topic 1.1)Read the Topic 1.1 guide on algorithms, sequencing, and the compile-run cycle. Write one example of each error type (syntax, logic, run-time) in your own words. Use the key terms list to check your definitions of compiler, logic error, and exception.
Step 2: Variables, expressions, assignment, and casting (Topics 1.2-1.5)Work through the topic guides for 1.2 through 1.5 in order. For each guide, write three practice expressions and trace their values by hand before checking. Focus on integer division, the (int) cast, widening conversion, and what happens at Integer.MAX_VALUE.
Step 3: Compound assignment operators (Topic 1.6)Read the Topic 1.6 guide and trace at least five sequences of compound assignment statements. Write out the variable value after every single statement. Practice with +=, *=, %=, x++, and x-- in combination.
Step 4: APIs, method signatures, and static methods (Topics 1.7-1.10)Read the guides for 1.7 through 1.10. Practice reading a method signature and writing a correct call. Distinguish void from non-void methods and instance methods from static methods. Use the Math class as your main example for static method calls.
Step 5: Objects, constructors, instance methods, and Strings (Topics 1.11-1.15)Read the guides for 1.11 through 1.15. Write code that creates a String object, calls each of the five Quick Reference String methods, and traces the output. Practice the Math.random() scale-and-shift formula. Then use available practice questions to test your ability to trace object creation and method calls under exam conditions.

More ways to review

Topic study guides

Open the individual guides for Unit 1 when you want a closer review of one topic.

browse guides

FRQ practice

Practice free-response reasoning and compare your answer with scoring guidance.

practice FRQs

Cheatsheets

Use unit cheatsheets for a quick visual review after you work through the notes.

open cheatsheets

Score calculator

Estimate your broader AP score goal after you review the course and exam format.

open calculator

Frequently Asked Questions

What topics are covered in AP CSA Unit 1?

AP CSA Unit 1 covers 15 topics that build the foundation of Java programming: algorithms and compilers, variables and data types, expressions and output, assignment statements and input, casting, compound assignment operators, APIs and libraries, documentation with comments, method signatures, calling class methods, the Math class, objects and instantiation, calling instance methods, and String manipulation. See the full topic list at AP CSA Unit 1.

How much of the AP CSA exam is Unit 1?

Unit 1 makes up 15-25% of the AP CSA exam, making it one of the most heavily weighted units. It covers core Java concepts like variables, data types, expressions, object creation, and String and Math class methods. A strong grasp of this unit directly supports your performance across the rest of the exam.

What's on the AP CSA Unit 1 progress check (MCQ and FRQ)?

The AP CSA Unit 1 progress check in AP Classroom includes both MCQ and FRQ parts drawn from the unit's 15 topics. MCQ questions test variables, data types, casting, expressions, compound assignment operators, and method signatures. FRQ questions focus on object creation, calling instance methods, and String manipulation. Reviewing those topics before attempting the progress check is the most efficient prep. Practice with aligned questions at AP CSA Unit 1.

How do I practice AP CSA Unit 1 FRQs?

AP CSA Unit 1 FRQs typically ask you to write or trace code involving object creation, calling instance methods, and String manipulation. To practice, write short Java programs that instantiate objects, call Math and String class methods, and use variables with correct data types. Check your output against expected results, then review any casting or method signature errors. Find practice FRQs at AP CSA Unit 1.

Where can I find AP CSA Unit 1 practice questions?

The best place to find AP CSA Unit 1 practice questions, including multiple-choice and practice test sets, is AP CSA Unit 1. That page has MCQ practice covering variables, data types, expressions, casting, compound assignment operators, APIs, and object instantiation, so you can test each topic before moving on. Mixing MCQ practice with short coding exercises on String and Math methods gives you the most complete prep.

How should I study AP CSA Unit 1?

Start with variables and data types, since every other topic in Unit 1 builds on them. Then work through expressions, assignment statements, and casting before moving to method signatures and APIs. Once those feel solid, practice calling Math and String class methods, then move to object creation and calling instance methods. Write small Java programs for each topic rather than just reading. Use the progress check MCQ to spot gaps, and revisit any topic where casting or method calls trip you up. Full topic guides are at AP CSA Unit 1.

Ready to review Unit 1?Start with the notes, check the topic cards, and use the practice or resource links when they are available for this course.