Reference Guide

A method’s signature decides which method Java runs. Knowing exactly what is (and is not) in a signature is the key to reading APIs and writing overloaded methods.

Key Topics

Term Definition Example
Method A named block of code that only runs when it is called. add(3, 4);
Method header The first line of a method: modifiers, return type, name, parameter list. public static int add(int a, int b)
Method signature Method name + ordered list of parameter types (AP scope). add(int, int)
Parameter A variable in the method header. It receives a value. int a
Argument The actual value passed in the method call. add(3, 4) (3 and 4)
Return type The type of value the method gives back, or void for none. Not part of the signature. int
Overloading Same method name, different parameter lists in one class. add(int) and add(int, int)
Procedural abstraction Using a method by knowing what it does, not how it is written. Math.abs(-5)
Call by value A primitive parameter gets a copy of the argument, so changing it does not change the original. bump(x) leaves x alone

What is in a Signature?

Part of the header Example In the signature?
Access modifier public No
static keyword static No
Return type int No
Method name add Yes
Parameter types (in order) int, int Yes
Parameter names a, b No

Picking the Right Method

  • Count the arguments, then check order, then check types.
  • Exact type match wins. If there is none, Java widens (int to double).
  • Java never narrows on its own (double to int needs a cast).
  • Same name + same parameter types + different return type = compile error.

College Board Requirements

AP CSA Unit 1, Topic 1.9 Method Signatures. From the course and exam description (College Board, 2025, p. 41): a method signature includes “the method name and the ordered list” of parameter types.

This lesson covers these Topic 1.9 ideas (paraphrased; check exact wording and numbering in the CED):

  • A method is a named block of code that runs only when it is called, and procedural abstraction lets you use a method without knowing how it is written.
  • A method signature is the method name plus the ordered list of parameter types. A method with no parameters has the name and an empty parameter list, such as reset().
  • Parameters are the variables in the method header. Arguments are the values passed in the call. The parameter list sets how many values, in what order, and of what types a call must supply.
  • Call by value: when an argument is a primitive value, the parameter starts as a copy of it, so changes to the parameter do not affect the original variable.
  • Methods are overloaded when they share a name but have different signatures. Java chooses the overload that matches the call’s arguments.
  • The return type (including void) is not part of the signature, so two methods cannot differ only by return type (Gosling et al., 2025, §§8.4.2, 8.4.9).

Lesson Plan

Learning Objective: Identify the parts of a method signature, tell parameters from arguments, and predict which overload gets called.

Success Criteria: Given a method header, you can state its signature and say whether another method could legally overload it.

Tech Talk

A method header has four parts, but Java only uses two of them to tell methods apart.

public static int add(int a, int b)

Part Example Note
Access modifier public Not part of the signature
Return type int Not part of the signature
Method name add Part of the signature
Parameter list (int a, int b) Types and order are part of the signature

Signature: add(int, int). Two methods can share a name only if their parameter lists differ. That is overloading.

Code Runner Challenge

Run it, then change an argument and predict which overload runs.

Code Runner Challenge

Run it, then change an argument and predict the new output

View IPYNB Source
// CODE_RUNNER: Run it, then change an argument and predict the new output
public class SigDemo {
    public static int add(int a, int b)          { return a + b; }  // add(int, int)
    public static double add(double a, double b) { return a + b; }  // add(double, double)
    public static int add(int a)                 { return a + 1; }  // add(int)

    public static void main(String[] args) {
        System.out.println(add(3, 4));   // 7   -> add(int, int)
        System.out.println(add(3.0, 4)); // 7.0 -> add(double, double), 4 widens
        System.out.println(add(5));      // 6   -> add(int)
    }
}

SigDemo.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Code Examples

A. Parameters vs arguments, and call by value

The ParamDemo class shows where parameters and arguments live, and that a primitive argument is copied.

Two words that get mixed up a lot:

Code Runner Challenge

Run it, then change the argument to addFive and predict what main prints

View IPYNB Source
public static void greet(String name, int times)   // name and times are PARAMETERS
greet("Sam", 2);                                    // "Sam" and 2 are ARGUMENTS
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Terminology: The signature of greet is greet(String, int). Parameter names are not part of it.

Code Runner Challenge

Run it, then add a call that has no matching overload and read the compiler error

View IPYNB Source
// CODE_RUNNER: Run it, then change the argument to addFive and predict what main prints
public class ParamDemo {
    // name and times are parameters
    public static void greet(String name, int times) {
        for (int i = 0; i < times; i++) {
            System.out.println("Hello, " + name + "!");
        }
    }

    // number is a copy of whatever argument is passed in
    public static void addFive(int number) {
        number = number + 5;
        System.out.println("Inside addFive: " + number);
    }

    public static void main(String[] args) {
        greet("Sam", 2);            // "Sam" and 2 are arguments

        int score = 10;
        addFive(score);             // score is copied into number
        System.out.println("Back in main: " + score);  // still 10
    }
}

ParamDemo.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

B. Overload resolution

The OverloadDemo class has several show methods. Java picks one by looking at the number, order, and types of the arguments.

Common overload mistakes:

Code Runner Challenge

Run it, then uncomment the illegal method and read the compiler error

View IPYNB Source
show(3, "a")    // matches show(int, String)
show("a", 3)    // matches show(String, int): order matters
half(9)         // no half(int), so the int 9 widens to 9.0 for half(double)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Terminology: Java widens int to double automatically, but it never narrows double to int without a cast.

Code Runner Challenge

Replace every "?" with your answer, then run it and compare

View IPYNB Source
// CODE_RUNNER: Run it, then add a call that has no matching overload and read the compiler error
public class OverloadDemo {
    public static void show(int x)           { System.out.println("show(int): " + x); }
    public static void show(double x)        { System.out.println("show(double): " + x); }
    public static void show(String s)        { System.out.println("show(String): " + s); }
    public static void show(int x, String s) { System.out.println("show(int, String): " + x + s); }
    public static void show(String s, int x) { System.out.println("show(String, int): " + s + x); }

    public static double half(double x)      { return x / 2; }

    public static void main(String[] args) {
        show(7);          // exact match: show(int)
        show(7.5);        // exact match: show(double)
        show("hi");       // exact match: show(String)
        show(3, "a");     // show(int, String)
        show("a", 3);     // show(String, int): order matters
        System.out.println(half(9));  // 4.5, the int 9 widens to 9.0

        // show(true);    // ERROR: no show(boolean) exists
    }
}

OverloadDemo.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

C. The return type is not part of the signature

The ReturnTypeDemo class has two legal total methods. A third one that changes only the return type would not compile.

Terminology: total(int, int) and total(double, double) have different signatures, so both can exist. int total(int, int) and double total(int, int) have the same signature, so Java rejects the second one.

Code Runner Challenge

Finish the overloaded methods, fill in the comments, then run it

View IPYNB Source
// CODE_RUNNER: Run it, then uncomment the illegal method and read the compiler error
public class ReturnTypeDemo {
    public static int total(int a, int b) { return a + b; }            // total(int, int)

    // Same name + same parameters, only the return type differs:
    // public static double total(int a, int b) { return a + b; }     // compile error

    public static double total(double a, double b) { return a + b; }  // total(double, double), legal

    public static void main(String[] args) {
        System.out.println(total(2, 3));    // 5    -> total(int, int)
        System.out.println(total(2.5, 3));  // 5.5  -> total(double, double)
    }
}

ReturnTypeDemo.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Hacks & Practice Tasks

Popcorn Hack

2-minute challenge: be the signature detective.

  1. Write the signature for each of the three headers.
  2. Predict which overload (A, B, C, or D) each of the four calls runs.
  3. Run the cell and compare your guesses with the real output.

Replace every "?" with your own answer.

// CODE_RUNNER: Replace every "?" with your answer, then run it and compare
//SignatureDetective
public class SignatureDetective {
    // Part 1: write each signature (name + parameter types only)
    // public int getScore(String name)                 ->
    String sig1 = "?";
    // public static double average(double a, double b) ->
    String sig2 = "?";
    // private void reset()                             ->
    String sig3 = "?";

    // Part 2: four overloads
    public static String pick(int x)        { return "A"; }
    public static String pick(double x)     { return "B"; }
    public static String pick(int x, int y) { return "C"; }
    public static String pick(String s)     { return "D"; }

    // Predict the letter each call prints BEFORE you run
    String guess1 = "?";  // pick(4)
    String guess2 = "?";  // pick(4.0)
    String guess3 = "?";  // pick(4, 5)
    String guess4 = "?";  // pick("4")

    public static void main(String[] args) {
        SignatureDetective d = new SignatureDetective();
        System.out.println("Signatures: " + d.sig1 + " | " + d.sig2 + " | " + d.sig3);
        System.out.println("Your guesses: " + d.guess1 + d.guess2 + d.guess3 + d.guess4);
        System.out.println("Actual:       " + pick(4) + pick(4.0) + pick(4, 5) + pick("4"));
    }
}

SignatureDetective.main(null);

MCQ Check

5 questions, one at a time. Answer, check, then go to the next one. At the end, copy your score line (for example 4/5 | answers: B,C,A,D,B) into your notes.

Question 1 of 5

What is the signature of public static int add(int a, int b)?

  • A. public static add(int, int)
  • B. add(int, int)
  • C. int add(int a, int b)
  • D. add(a, b)
Check answer **B.** The signature is only the name and the ordered parameter types. Modifiers, return type, and parameter names are not included.

Question 2 of 5

Given static int square(int n) and the call int r = square(4);, which one is the argument?

  • A. n
  • B. square
  • C. 4
  • D. r
Check answer **C.** `n` is the parameter (in the header). `4` is the argument (the value passed in the call).

Question 3 of 5

Which pair of methods can legally exist in the same class?

  • A. void show(int a, String b) and void show(String a, int b)
  • B. int calc(int x) and double calc(int x)
  • C. void show(int a) and void show(int b)
  • D. public void go() and private void go()
Check answer **A.** The parameter types are in a different order, so the signatures differ. B differs only by return type, C only by parameter name, and D only by access modifier, so those are all compile errors.

Question 4 of 5

A class has static String label(double x) and static String label(String s). What happens with the call label(5)?

  • A. It calls label(String)
  • B. Compile error
  • C. Runtime exception
  • D. It calls label(double), and 5 widens to 5.0
Check answer **D.** No `label(int)` exists, so Java widens the `int` to a `double` and uses `label(double)`.

Question 5 of 5

static void bump(int n) { n = n + 1; }
// in main:
int x = 5;
bump(x);
System.out.println(x);

What prints?

  • A. 6
  • B. 5
  • C. Compile error
  • D. 1
Check answer **B.** Call by value: `n` is a copy of `x`. Changing the copy does not change `x`.

Homework Hack

Task: Finish the two overloaded area methods. Above each method, write its signature in a comment. Then run the calls in main. For the third call, area(3), write a one-line comment explaining which overload runs and why.

// CODE_RUNNER: Finish the overloaded methods, fill in the comments, then run it
public class HomeworkStarter {
    // Signature: ?
    public static double area(double radius) {
        return 0.0; // TODO: circle area (use Math.PI)
    }

    // Signature: ?
    public static int area(int width, int height) {
        return 0; // TODO: rectangle area
    }

    public static void main(String[] args) {
        System.out.println(area(3.0));  // expected: ~28.27
        System.out.println(area(3, 4)); // expected: 12
        System.out.println(area(3));    // predict first
        // My answer for area(3): ?
    }
}

HomeworkStarter.main(null);

References

College Board. (2025). AP Computer Science A course and exam description [Effective fall 2025]. https://apcentral.collegeboard.org/media/pdf/ap-computer-science-a-course-and-exam-description-effective-fall-2025.pdf

Gosling, J., Joy, B., Steele, G., Bracha, G., Buckley, A., Smith, D., & Bierman, G. (2025). The Java language specification: Java SE 25 edition (Secs. 8.4.2, 8.4.9). Oracle. https://docs.oracle.com/javase/specs/jls/se25/html/jls-8.html#jls-8.4.2

All Java lessons