01
Overview

Parameters: the inputs that make methods reusable.

Parameters let one method handle many cases — different inputs, same logic, predictable behavior.

A parameter is a variable declared in a method's header. When the method is called, the caller supplies an argument — an actual value — and Java copies that value into the parameter.

Without parameters, every method would be hard-coded to one specific case. Parameters are why Math.pow(2, 3) and Math.pow(5, 4) can share the same body but compute different results.

On the AP exam, parameters appear in code tracing, in method-design FRQs, and in tricky questions about how Java passes values to methods.

02
Core Concept

Java passes by value — always.

For primitives, the value is the data. For objects, the value is the reference.

Formal vs actual parameters

// Formal parameters: x and y
public static int sum(int x, int y) {
    return x + y;
}

// Actual arguments: 3 and 4
int total = sum(3, 4);

The names x and y are the formal parameters declared in the header. The values 3 and 4 are the actual arguments passed at the call site.

Pass-by-value rule

Java always passes by value. For a primitive, the parameter gets a copy of the value, so changes inside the method don't affect the caller.

public static void change(int n) {
    n = 100;
}

int a = 5;
change(a);
System.out.println(a);   // prints 5 — unchanged

Pass-by-value with objects

For objects, the parameter still receives a copy — but it's a copy of the reference. So the method can mutate the object's fields, but cannot make the caller's variable point to a different object.

public static void grow(Rectangle r) {
    r.setWidth(r.getWidth() + 1);   // affects caller's object
    r = new Rectangle(0, 0);        // does NOT affect caller's variable
}

Order and type matching

Arguments are matched to parameters by position, not name. Their types must be compatible: passing a double where an int is expected is a compile error.

03
Key Vocabulary

The exact words AP uses.

Know these to read questions precisely.

Vocabulary
  • Parameter — a variable declared in the method header.
  • Formal parameter — same as parameter; emphasises it is a placeholder.
  • Argument — the actual value passed in at the call site.
  • Actual parameter — another name for argument.
  • Pass by value — Java's only mode: the parameter gets a copy of the argument's value.
  • Method signature — method name plus the ordered list of parameter types.
  • Overloading — two methods with the same name but different parameter lists.
  • Scope — parameters exist only inside their method.
04
AP Exam Focus

How parameters appear on the AP exam.

Expect pass-by-value tracing, mutating-object questions, and signature matching.

Exam Focus

MCQ patterns to expect:

  • Primitives don't change. Modifying a primitive parameter inside a method never affects the caller's variable.
  • Object fields can change. If a method mutates an object's state through its reference, the caller sees the changes.
  • Reassigning a reference parameter only changes the local copy, not the caller's reference.
  • Overload resolution. Java picks the method whose parameter types match the arguments most closely.

FRQ tip: when writing a method header, get parameter types and order exactly right. The signature is graded.

05
Worked Example

Trace a pass-by-value question.

Distinguish what changes from what only appears to change.

Worked Example AP-style reasoning

Problem. Assume Box has a field size with getter and a method setSize(int). What is printed?

public static void modify(int n, Box b) {
    n = n + 1;
    b.setSize(b.getSize() + 1);
    b = new Box(100);
}

int x = 5;
Box box = new Box(10);
modify(x, box);
System.out.println(x + " " + box.getSize());

Step 1. Inside modify: n is a copy of x's value. n = n + 1 changes only n, not x. So x stays 5.

Step 2. b is a copy of the reference to the same Box object. b.setSize(b.getSize() + 1) mutates that shared object — its size becomes 11.

Step 3. b = new Box(100) reassigns the local b to a new object. The caller's box reference is unaffected.

Step 4. Back in the caller: x = 5 and box.getSize() = 11.

Answer. The program prints 5 11.

Why this matters. Primitives cannot be mutated through a method, but objects can — as long as you mutate the existing object instead of reassigning the parameter.

06
Common Mistakes

Parameter errors that lose points.

The biggest mistake is assuming Java passes by reference.

Watch Out
  • "Pass by reference" myth. Java never passes by reference. It passes by value — for objects, that value happens to be a reference.
  • Trying to swap two ints via a method. Impossible in Java; the swap only happens to the local copies.
  • Reassigning a parameter and expecting the caller's variable to change. It won't.
  • Wrong argument types or order. Java matches by position and type, not by name.
  • Passing the wrong number of arguments. Compile error.
  • Mutating a parameter when the caller didn't expect it. For object parameters, document clearly whether you'll mutate.
07
Reference Table

Parameter behavior summary.

Use this to decode any pass-by-value question.

Parameters Reference

AP Quick Reference
Action inside method Effect on caller (primitive) Effect on caller (object)
Assign new value to parameter No effect No effect (only local copy changes)
Call a mutating method on parameter N/A — primitives have no methods Caller's object IS changed
Read the parameter Reads the copied value Reads through the shared reference
Create a new object and assign to parameter N/A Caller's reference unchanged
Pass null as argument Compile error for primitives Parameter is null inside method
08
Practice Tip

How to internalize parameter behavior.

A small memory diagram beats any rule of thumb.

Practice Strategy

Use the three practice tools below this lesson in order:

  • MCQ Practice — sketch boxes for each parameter and arrow each one to its value or object. Watch what happens to the caller's variable as the method runs.
  • Java Lab — write methods that take primitives and methods that take objects. Test that primitive parameters cannot be mutated, but object fields can.
  • FRQ Practice — match the method header exactly as the problem states it. Parameter types, names, and order all matter for partial credit.

If you can answer "what does the caller see after the call?" precisely, you've mastered parameters.

09
Section · 09

Practice — attempt these now.

AP-style assessments aligned to this lesson. Time them.

Topic Quiz 30 min 30 marks Pending

AP CSA Topic Practice: Parameters

AP-style topic practice assessment

Start
FRQ Practice 30 min 18 marks Pending

AP CSA Unit 01 Topic 03 Parameters FRQ Practice

AP-style topic practice assessment

Start