Topic 1.9 — Method Signatures

Goal: read and interpret method signatures, identify method names, parameter types/order, and return types, and understand how signatures help you call methods correctly.

The big idea

A method signature is the “shape” of a method: its name + the parameter list (types and order). The signature tells you how to call the method.

In CSA, you’ll constantly read signatures from the Java API to know what inputs a method needs and what it returns.

What you can learn from a signature

  • Method name (exact spelling and capitalization)
  • Parameter types and parameter order
  • Return type (what you get back, or void if nothing)

Signature anatomy (template)

returnType methodName(type1 p1, type2 p2, ...)

The parameter names (p1, p2) don’t matter when calling the method—only the types and order matter.

Quick note

People sometimes use “signature” to mean just name + parameters. But for AP CSA, it’s most important that you can read the whole line: name, parameters, and return type.

Examples you should be able to interpret

Example A

int length()
  • Name: length
  • Parameters: none
  • Return type: int

Example B

double pow(double a, double b)
  • Name: pow
  • Parameters: two double values (in order)
  • Return type: double

Example C

void println(String x)
  • Name: println
  • Parameters: one String
  • Return type: void (nothing returned)

Example D

String substring(int beginIndex, int endIndex)
  • Returns: a String
  • Takes: two int parameters (order matters)

How signatures help you call methods correctly

When you call a method, you must match:

  • the correct method name
  • the correct number of arguments
  • the correct argument types
  • the correct argument order

Common errors from signature mismatches

  • Wrong name → compile-time error
  • Wrong number of arguments → compile-time error
  • Wrong types → compile-time error
  • Right call, but ignoring return value → logic error

Return types: store vs. use directly

If a method returns a value, you can store it or use it in an expression.

// Store it
int n = someString.length();

// Use it directly
int total = someString.length() + 5;

Exam mindset

  • Read method calls by matching them to a signature.
  • Return type tells you what kind of variable can store the result.
  • Parameter list tells you how many arguments and what types to pass.
  • If the return type is void, you can’t assign it to a variable.

Quick self-check

  1. In double pow(double a, double b), what is the method name?
  2. How many parameters does it have?
  3. What does the return type tell you?
  4. Why does argument order matter?
  5. What does void mean in a signature?

← Back to Unit 1 topics