AP CSA Unit 1: Using Objects and Methods - Complete Study Guide

AP Computer Science A – Unit 1: Using Objects and Methods (2025)

Unit 1 introduces the building blocks of Java programs: variables, data types, expressions, input/output, the Math class, APIs, objects, and method calls. Everything else in AP CSA builds on these ideas, so this is the unit where you set yourself up for a 4 or 5.

📘 1.1 Unit Overview & Exam Context

In the 2025 AP Computer Science A Course and Exam Description (CED), Unit 1: Using Objects and Methods accounts for about 15–25% of the multiple-choice exam. Even though it's the first unit, it introduces concepts you’ll use all year:

  • Variables, data types, and expressions
  • Assignment and simple input/output
  • Casting and the range of primitive types
  • Compound assignment operators (like +=)
  • Documentation with comments
  • APIs and libraries (like the Java standard library)
  • Method signatures and method calls (including class/static methods)
  • The Math class and basic numerical methods
  • Objects, instantiation, and calling instance methods
  • String objects and common string operations
Why Unit 1 matters: If you can confidently create variables, call methods, and reason about objects and Strings, you’ll be in excellent shape for later topics like iteration, arrays, ArrayLists, and FRQs.

 

 

🧠 1.2 Algorithms, Programs, and Compilers

An algorithm is a step-by-step process for solving a problem. A program is how we express that algorithm in a programming language (like Java).

Compiler vs. Source Code

Java is a compiled language. You write source code in .java files. Then, the compiler translates this code into bytecode that runs on the Java Virtual Machine (JVM).

Plain English Algorithm: 1. Ask the user for their age. 2. Add 1. 3. Print "Next year you will be " + (age + 1). ↓ translated into Java code ↓ int age = input.nextInt(); int next = age + 1; System.out.println("Next year you will be " + next);
On the AP exam, you don’t need to know all compiler internals, but you must understand that Java source code must be translated before the computer can execute it.

 

 

🔤 1.3 Variables, Data Types, and Expressions

A variable is a named storage location in memory. Every variable has:

  • A type (what kind of data it holds)
  • A name
  • A value

Primitive Data Types (AP Required)

Type Description Example
int Integer value int count = 10;
double Decimal number double price = 4.99;
boolean true or false boolean done = false;
char Single character char grade = 'A';

Expressions & Operators

An expression combines variables, values, and operators to produce a result:

int x = 5;
int y = 2;
int sum = x + y;        // 7
int product = x * y;    // 10
double avg = (x + y) / 2.0;  // 3.5
AP Tip: Know the difference between integer division and floating-point division. 5 / 2 is 2, but 5 / 2.0 is 2.5.

 

 

📥 1.4 Assignment, Input, Casting & Compound Operators

Assignment Statements

The = symbol in Java means “assign”, not “equals in math”.

int a = 10;
a = a + 5;   // now a is 15

Simple Input (Scanner)

AP CSA expects you to understand the idea of input, often with Scanner:

Scanner input = new Scanner(System.in);
int age = input.nextInt();

Casting & Range

Casting converts between compatible types:

double d = 5.8;
int n = (int) d;  // n is 5 (fraction is discarded)
Casting from double to int truncates (drops) the decimal part — it does not round.

Compound Assignment

These operators update and assign in one step:

x += 3;   // x = x + 3
x -= 2;   // x = x - 2
x *= 4;   // x = x * 4
x /= 5;   // x = x / 5

 

 

📄 1.5 Comments, APIs & Method Signatures

Comments & Documentation

Comments help explain your code to humans (they are ignored by the compiler):

// This is a single-line comment

/*
   This is a
   multi-line comment
*/
Writing clear comments is part of good programming style and can be especially helpful on FRQs.

APIs & Libraries

An API (Application Programming Interface) tells you:

  • What methods are available
  • What parameters they take
  • What types they return

For example, the String API shows methods like length(), substring(), indexOf(), equals(), and compareTo().

Method Signatures

A method signature includes the method name and parameter types:

public static int max(int a, int b)
  • Return type: int
  • Method name: max
  • Parameters: two ints (a, b)
The AP exam expects you to read unfamiliar method signatures and call them correctly.

 

 

🧮 1.6 Class (Static) Methods & the Math Class

A class method (also called a static method) belongs to the class itself, not to a particular object. You call these using ClassName.methodName(...).

Math Class Basics

double root = Math.sqrt(25);   // 5.0
double pow  = Math.pow(2, 3);  // 8.0
double abs  = Math.abs(-4.5);  // 4.5

Math.random() returns a double in the range [0.0, 1.0) (0 inclusive, 1 exclusive).

Random Integer in a Range

// 0 to n-1
int r1 = (int)(Math.random() * n);

// 1 to n
int r2 = (int)(Math.random() * n) + 1;

// a to b inclusive
int r3 = (int)(Math.random() * (b - a + 1)) + a;
AP Tip: Always test your range formulas with the smallest and largest possible values from Math.random(): 0.0 and just under 1.0.

 

 

🧱 1.7 Objects, Instantiation & References

Java is an object-oriented language. Many things you work with are objects: String, Scanner, Random, and eventually your own classes.

Creating Objects (Instantiation)

Scanner input = new Scanner(System.in);
Random rand = new Random();
String name = new String("APCSA"); // usually just: String name = "APCSA";

The new keyword creates (instantiates) an object in memory and returns a reference to it. That reference is stored in the variable.

Think of this mental model: Scanner input = new Scanner(System.in); +-----------+ +------------------------+ | input | ---> | Scanner object in heap | +-----------+ +------------------------+ The variable holds a reference (arrow), not the entire object.
This idea (variables storing references to objects) is crucial later when you pass objects to methods or assign one object variable to another.

 

 

📞 1.8 Calling Instance Methods

An instance method is a method you call on a specific object instance:

String word = "hello";
int len = word.length();          // instance method
String upper = word.toUpperCase();

General pattern:

objectVariable.methodName(parameters);

More Examples

Scanner input = new Scanner(System.in);
int value = input.nextInt();   // calls nextInt() on that Scanner

Random rand = new Random();
int r = rand.nextInt(10);      // 0–9
On the AP exam, you'll be asked to interpret method calls, determine parameter types, and predict return values.

 

 

🧵 1.9 Strings & String Manipulation

String is one of the most important classes in AP CSA. It represents a sequence of characters like "hello" or "AP CSA".

Key Ideas About Strings

  • Strings are objects, not primitive types.
  • Strings are immutable – they cannot be changed after creation.
  • Many AP questions involve substring, indexOf, equals, and compareTo.

Common String Methods

String s = "computer";

// length
int n = s.length();          // 8

// substring
String sub1 = s.substring(0, 3); // "com"
String sub2 = s.substring(3);    // "puter"

// indexOf
int idx1 = s.indexOf("pu");  // 3
int idx2 = s.indexOf("x");   // -1 (not found)

// equality
boolean b1 = s.equals("computer");  // true
boolean b2 = s.equals("Computer");  // false (case-sensitive)
Never use == to compare two Strings. Use equals() instead, because == compares references, not contents.

String compareTo

"apple".compareTo("banana");   // negative (apple comes before banana)
"zoo".compareTo("ant");        // positive (zoo comes after ant)
"java".compareTo("java");      // 0 (equal)

You rarely care about the exact number—just whether it is negative, zero, or positive.

 

 

🧩 1.10 Putting It All Together – Practice Examples

Example 1 – Using Math and Strings

int a = 7;
int b = 3;
double avg = (a + b) / 2.0;
String msg = "Average: " + avg;
System.out.println(msg);

Output: Average: 5.0

Example 2 – Simple Input and Output

Scanner input = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = input.nextLine();

System.out.println("Hello " + name + "!");

Example 3 – String + Random

Random rand = new Random();
String[] prizes = {"Sticker", "Pen", "Notebook"};
int index = rand.nextInt(prizes.length);
System.out.println("You won: " + prizes[index]);
These “combine everything” examples are similar to early AP CSA MCQs and helpful warm-ups for FRQs.

 

 

⚠️ 1.11 Common Unit 1 Mistakes

  • Using == instead of equals() for Strings
  • Forgetting integer vs. double division rules
  • Assuming Math.random() includes 1.0
  • Forgetting that String methods don’t modify the original string (immutability)
  • Misreading method signatures (wrong parameter types or order)
  • Confusing variables that hold values vs. variables that hold object references
When practicing, always ask yourself: “Is this a primitive or an object? Does this method change something, or does it return a new value?”

 

 

📝 Unit 1 Quiz – Using Objects and Methods (10 Questions)

Question 1

What is printed by the following code?

int a = 5;
int b = 2;
double result = a / b;
System.out.println(result);
  • A. 2.0
  • B. 2.5
  • C. 3.0
  • D. 3

Question 2

Which of the following correctly creates a Scanner object to read from the keyboard?

  • A. Scanner input = new Scanner();
  • B. Scanner input = new Scanner(System.in);
  • C. Scanner = new Scanner(System.in);
  • D. new Scanner input = Scanner(System.in);

Question 3

What best describes the purpose of an API in Java?

  • A. It automatically fixes syntax errors.
  • B. It describes available classes, methods, and how to use them.
  • C. It converts Java code to machine code.
  • D. It creates random numbers for testing.

Question 4

What is the value of x after this code runs?

int x = 10;
x += 3;
x -= 4;
  • A. 7
  • B. 9
  • C. 13
  • D. 14

Question 5

Which expression correctly generates a random integer from 1 to 6 inclusive?

  • A. (int)(Math.random() * 6)
  • B. (int)(Math.random() * 6) + 1
  • C. (int)(Math.random() * 5) + 1
  • D. (int)(Math.random() * 7) + 1

Question 6

What is printed?

String s = "APCSA";
System.out.println(s.substring(1, 4));
  • A. "APC"
  • B. "PCS"
  • C. "CSA"
  • D. "PCSA"

Question 7

Which of the following compares two strings for equal text?

  • A. str1 == str2
  • B. str1.equals(str2)
  • C. str1 = str2
  • D. str1.compareTo(str2) == 1

Question 8

Which of the following is a valid method signature?

  • A. public int method(String x, int y)
  • B. public method(String x, int y)
  • C. public static void(int x)
  • D. int method(x, y)

Question 9

What is printed?

String s = "hello";
s.toUpperCase();
System.out.println(s);
  • A. "hello"
  • B. "HELLO"
  • C. "Hello"
  • D. Causes a runtime error

Question 10

Which statement about objects and primitives is TRUE?

  • A. Primitive variables hold references, objects hold values.
  • B. Both primitives and objects are referenced with new.
  • C. Primitive variables hold actual values; object variables hold references.
  • D. Only objects can be passed to methods.

 

 

🚀 Next Steps: Move on to Unit 2 – Selection and Iteration

Once you're comfortable with variables, expressions, objects, method calls, and Strings, you’re ready for Unit 2: Selection and Iteration, where you’ll learn how to make decisions with if statements and repeat actions with loops.

On your site, link to your Unit 2 page here, for example:
Continue to AP CSA Unit 2: Selection and Iteration

Contact form