---
title: "AP CSA Unit 1 Review: Using Objects and Methods | Fiveable"
description: "AP Computer Science A Unit 1 covers Why Programming? Why Java? and Variables and Primitive Data Types. Study guides, practice questions, and key terms."
canonical: "https://fiveable.me/ap-comp-sci-a/unit-1"
type: "unit"
subject: "AP Computer Science A"
unit: "Unit 1 – Using Objects and Methods"
---

# AP CSA Unit 1 Review: Using Objects and Methods | Fiveable

## Overview

Unit 1 introduces Java programming from the ground up. You learn how algorithms are represented, how Java code compiles and runs, how to declare and use variables of primitive and reference types, how arithmetic and assignment work, and how to create and use objects. The unit ends with the Math and String classes, which are tested directly on the exam.

## AP CED Alignment

This unit hub is organized around AP Course and Exam Description topics, skills, and exam task types when they are available in the source data.
- 1.1: Introduction to Algorithms, Programming, and Compilers
- 1.2: Variables and Data Types
- 1.3: Expressions and Output
- 1.4: Assignment Statements and Input
- 1.5: Casting and Range of Variables
- 1.6: Compound Assignment Operators
- 1.7: Application Program Interface (API) and Libraries
- 1.8: Documentation with Comments
- 1.9: Method Signatures
- 1.10: Calling Class Methods
- 1.11: Math Class
- 1.12: Objects: Instances of Classes
- 1.13: Object Creation and Storage (Instantiation)
- 1.14: Calling Instance Methods
- 1.15: String Manipulation
- 1.1: Algorithms, compilation, and error types
- 1.2: Variables and primitive data types
- 1.3: Expressions, output, and operator precedence
- 1.4-1.5: Assignment, casting, and variable ranges
- 1.6: Compound assignment operators
- 1.7-1.8: APIs, libraries, and documentation
- 1.9-1.10: Method signatures, calling methods, and static methods
- 1.11: Math class methods
- 1.12-1.13: Classes, objects, and constructors
- 1.14: Calling instance methods
- 1.15: String objects and String methods
- Practice 1 - Design Code
- Practice 2 - Develop Code
- Practice 4 - Document Code and Computing Systems
- Practice 3 - Analyze Code
- FRQ 1 – Methods and Control Structures

## Topics

- [1.1: Introduction to Algorithms, Programming, and Compilers](/ap-comp-sci-a/unit-1/why-programming-why-java/study-guide/lVK6rmrBuug17i1Hna9z): 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.
- [1.2: Variables and Data Types](/ap-comp-sci-a/unit-1/variables-and-primitive-data-types/study-guide/rezA6f3hJz84TKaY5Jjl): 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.
- [1.3: Expressions and Output](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr): 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.
- [1.4: Assignment Statements and Input](/ap-comp-sci-a/unit-1/14-assignment-statement-input/study-guide/compoundassignment): 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.
- [1.5: Casting and Range of Variables](/ap-comp-sci-a/unit-1/casting-and-ranges-of-variables/study-guide/kW3XXEIwJwVRXFx3ntdC): 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.
- [1.6: Compound Assignment Operators](/ap-comp-sci-a/unit-1/compound-assignment-operators/study-guide/JiszeHqK8F9G6gszbgPL): 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.
- [1.7: Application Program Interface (API) and Libraries](/ap-comp-sci-a/unit-1/application-program-interface-api-and-libraries/study-guide/sEpH1rg9TzREJwynSE9N): 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.
- [1.8: Documentation with Comments](/ap-comp-sci-a/unit-1/documentation-with-comments/study-guide/scrDad77j4e5vwrFab5J): Java supports single-line (//), block (/* */), and Javadoc (/** */) comments. Comments are ignored by the compiler. Preconditions and postconditions document what a method requires and guarantees.
- [1.9: Method Signatures](/ap-comp-sci-a/unit-1/calling-void-method-with-parameters/study-guide/QVWxxGeVjbIbLpC10d1Y): 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.
- [1.10: Calling Class Methods](/ap-comp-sci-a/unit-1/calling-non-void-method/study-guide/gXkdn6sNrkDRHZsCVN1x): 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.
- [1.11: Math Class](/ap-comp-sci-a/unit-1/using-the-math-class/study-guide/6e652tzJOa5eE5mjPATE): 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.
- [1.12: Objects: Instances of Classes](/ap-comp-sci-a/unit-1/objects-instances-of-classes/study-guide/EcpFHGcIKu6385hMohLe): 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.
- [1.13: Object Creation and Storage (Instantiation)](/ap-comp-sci-a/unit-1/creating-and-storing-objects/study-guide/rUOTKl6Ih5noXJ0GtxJF): 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.
- [1.14: Calling Instance Methods](/ap-comp-sci-a/unit-1/calling-a-void-method/study-guide/0RaM4GVOnbikS9dDp971): Call instance methods with objectReference.methodName(args). Each object uses its own data. Calling a method on a null reference throws NullPointerException at runtime.
- [1.15: String Manipulation](/ap-comp-sci-a/unit-1/string-methods/study-guide/SltCtk8JxBIgHcMfG6G4): 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.

## Hardest Topics And Analytics

Snapshot: practice snapshot
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.5k MCQ attempts** (Practice activity included in this snapshot.)

## 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.

**Checkpoint:** 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 type | When detected | Example
--- | --- | ---
Syntax error | Compile time | Missing semicolon, unclosed brace
Logic error | Testing (not compiler) | Wrong formula produces bad output
Run-time error | During execution | Integer divide by zero
Exception | During execution | NullPointerException, 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.

**Checkpoint:** 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.

Type | Category | Example values
--- | --- | ---
int | Primitive | 0, -5, 1000
double | Primitive | 3.14, -0.5, 2.0
boolean | Primitive | true, false
String | Reference | "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.

**Checkpoint:** Predict the output of: System.out.println(7 / 2 + " " + 7 % 2 + " " + 7.0 / 2);

### 1.4-1.5: 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.

**Checkpoint:** 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.

**Checkpoint:** If x = 10, what is x after x *= 3; then x %= 7;? Trace each step.

### 1.7-1.8: 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.

**Checkpoint:** 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-1.10: 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.

**Checkpoint:** 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 type | Called on | Syntax example | Returns value?
--- | --- | --- | ---
Static (class) method | Class name | Math.sqrt(9.0) | Yes (double)
Instance method | Object reference | str.length() | Yes (int)
Void method | Class or object | System.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.

**Checkpoint:** Write an expression that generates a random integer from 1 to 6 inclusive, simulating a die roll.

### 1.12-1.13: 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.

**Checkpoint:** 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.

**Checkpoint:** 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.

**Checkpoint:** For String s = "computer"; what does s.substring(0, 4) return? What does s.indexOf("put") return? What does s.length() return?

## Study Guides

- [1.5 Casting and Ranges of Variables](/ap-comp-sci-a/unit-1/casting-and-ranges-of-variables/study-guide/kW3XXEIwJwVRXFx3ntdC)
- [1.3 Expressions and Assignment Statements](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr)
- [1.7 Application Program Interface (API) and Libraries](/ap-comp-sci-a/unit-1/application-program-interface-api-and-libraries/study-guide/sEpH1rg9TzREJwynSE9N)
- [1.11 Using the Math Class](/ap-comp-sci-a/unit-1/using-the-math-class/study-guide/6e652tzJOa5eE5mjPATE)
- [1.14 Calling a Void Method](/ap-comp-sci-a/unit-1/calling-a-void-method/study-guide/0RaM4GVOnbikS9dDp971)
- [1.13 Creating and Storing Objects](/ap-comp-sci-a/unit-1/creating-and-storing-objects/study-guide/rUOTKl6Ih5noXJ0GtxJF)
- [1.2 Variables and Primitive Data Types](/ap-comp-sci-a/unit-1/variables-and-primitive-data-types/study-guide/rezA6f3hJz84TKaY5Jjl)
- [1.1 Why Programming? Why Java?](/ap-comp-sci-a/unit-1/why-programming-why-java/study-guide/lVK6rmrBuug17i1Hna9z)
- [1.6 Compound Assignment Operators](/ap-comp-sci-a/unit-1/compound-assignment-operators/study-guide/JiszeHqK8F9G6gszbgPL)
- [1.8 Documentation With Comments](/ap-comp-sci-a/unit-1/documentation-with-comments/study-guide/scrDad77j4e5vwrFab5J)
- [1.15 String Methods](/ap-comp-sci-a/unit-1/string-methods/study-guide/SltCtk8JxBIgHcMfG6G4)
- [1.9 Calling a Void Method With Parameters](/ap-comp-sci-a/unit-1/calling-void-method-with-parameters/study-guide/QVWxxGeVjbIbLpC10d1Y)
- [1.10 Calling a Non-Void Method](/ap-comp-sci-a/unit-1/calling-non-void-method/study-guide/gXkdn6sNrkDRHZsCVN1x)
- [1.12 Objects: Instances of Classes](/ap-comp-sci-a/unit-1/objects-instances-of-classes/study-guide/EcpFHGcIKu6385hMohLe)
- [1.4 Assignment Statements and Input](/ap-comp-sci-a/unit-1/14-assignment-statement-input/study-guide/compoundassignment)

## Practice Preview

### Multiple-choice practice

- **AP-style practice question**: Practice 1 - Design Code | 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?
- **AP-style practice question**: Practice 2 - Develop Code | 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?
- **AP-style practice question**: Practice 4 - Document Code and Computing Systems | Consider the following code segment.

```java
int num = 572;
int res = (num % 10) * 100 + ((num / 10) % 10) * 10 + (num / 100);
```

Which of the following best describes the behavior of the code segment?
- **AP-style practice question**: Practice 3 - Analyze Code | The following method is intended to read three integer scores from the user and calculate their sum. However, the code will not compile. Which of the following changes will correct the compilation error so the code works as intended?

```java
Scanner input = new Scanner(System.in);
int total; // line 2
for (int i = 0; i < 3; i++) {
    System.out.print("Enter score: ");
    total = total + input.nextInt(); // line 5
}
```
- **AP-style practice question**: Practice 1 - Design Code | An oven preheating algorithm needs to accept a target temperature (which can include decimal values) and return whether the oven has successfully reached that temperature. A programmer is designing an `Oven` class to represent this process. Which of the following method signatures is most appropriate for this task?
- **AP-style practice question**: Practice 2 - Develop Code | The following code segment is intended to calculate a final score based on a base value, a multiplier, and a bonus.

```java
int base = 4;
int mult = 3;
int bonus = 5;
/* missing code */
```

The intended algorithm is to first add the bonus to the base, then multiply that sum by the multiplier, and finally divide the result by 2. Which of the following can replace `/* missing code */`?

### FRQ practice

- **Event sequence tracking and keyword counting**: FRQ 1 – Methods and Control Structures | Event sequence tracking and keyword counting

## Key Terms

- **compiler**: A program that translates Java source code into a runnable form and detects syntax errors before the program executes.
- **logic error**: A mistake in the algorithm that causes incorrect output; the program compiles and runs but produces an unexpected result, detected only through testing.
- **arithmetic expression**: A combination of numeric values, variables, and operators (+, -, *, /, %) that evaluates to a single int or double result following operator precedence rules.
- **integer division**: Division of two int values that discards the fractional part: 7 / 2 evaluates to 3, not 3.5.
- **remainder operator**: The % operator returns the remainder after division: 7 % 3 evaluates to 1. Useful for divisibility checks and cycling through ranges.
- **cast operator**: Syntax 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 error**: A 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 instantiation**: Creating 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 reference**: The value stored in a reference-type variable: a memory address pointing to an object on the heap, not the object's data directly.
- **null reference**: A reference variable that does not point to any object. Calling a method on a null reference causes a NullPointerException at runtime.
- **call by value**: The 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 method**: A 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 literal**: A sequence of characters enclosed in double quotes, such as "hello", used to create a String object directly in code.
- **operator precedence**: The rules that determine evaluation order in a compound expression: *, /, and % are evaluated before + and -. Parentheses override the default order.

## Common 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.

## Exam Connections

- **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 Review Checklist

- **Identify and classify error types**: Given 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 type**: Write 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 casting**: Evaluate 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 operators**: Given 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 call**: Given 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 methods**: Write 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 Reference**: Write 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.

## Study Plan

- **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](/ap-comp-sci-a/unit-1#topics)
- [FRQ practice](/ap-comp-sci-a/frq-practice)
- [Cheatsheets](/ap-comp-sci-a/cheatsheets/unit-1)
- [Key terms](/ap-comp-sci-a/key-terms)

## FAQs

### 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](/ap-comp-sci-a/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](/ap-comp-sci-a/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](/ap-comp-sci-a/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](/ap-comp-sci-a/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](/ap-comp-sci-a/unit-1).

## Structured Data

```json
{"@context":"https://schema.org","@type":"FAQPage","inLanguage":"en","mainEntity":[{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-1#what-topics-are-covered-in-ap-csa-unit-1","name":"What topics are covered in AP CSA Unit 1?","acceptedAnswer":{"@type":"Answer","text":"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 <a href=\"/ap-comp-sci-a/unit-1\">AP CSA Unit 1</a>."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-1#how-much-of-the-ap-csa-exam-is-unit-1","name":"How much of the AP CSA exam is Unit 1?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-1#whats-on-the-ap-csa-unit-1-progress-check-mcq-and-frq","name":"What's on the AP CSA Unit 1 progress check (MCQ and FRQ)?","acceptedAnswer":{"@type":"Answer","text":"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 <a href=\"/ap-comp-sci-a/unit-1\">AP CSA Unit 1</a>."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-1#how-do-i-practice-ap-csa-unit-1-frqs","name":"How do I practice AP CSA Unit 1 FRQs?","acceptedAnswer":{"@type":"Answer","text":"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 <a href=\"/ap-comp-sci-a/unit-1\">AP CSA Unit 1</a>."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-1#where-can-i-find-ap-csa-unit-1-practice-questions","name":"Where can I find AP CSA Unit 1 practice questions?","acceptedAnswer":{"@type":"Answer","text":"The best place to find AP CSA Unit 1 practice questions, including multiple-choice and practice test sets, is <a href=\"/ap-comp-sci-a/unit-1\">AP CSA Unit 1</a>. 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."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-1#how-should-i-study-ap-csa-unit-1","name":"How should I study AP CSA Unit 1?","acceptedAnswer":{"@type":"Answer","text":"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 <a href=\"/ap-comp-sci-a/unit-1\">AP CSA Unit 1</a>."}}]}
```
