What is the difference between a parameter and an argument in Java?
answer
- Parameter = declared placeholder (in the method header)
- Argument = actual value (at the call site)
- Define parameters, pass arguments
- Arguments are copied into parameters (pass-by-value)
- Matched positionally, left to right
basics
~20 sA parameter is the variable named in the method declaration (the placeholder). An argument is the actual value you pass when you call the method. Parameters are in the definition; arguments are at the call.
solid answer
~40 sA parameter (sometimes 'formal parameter') is the named variable declared in a method's parameter list — the placeholder that exists inside the method, e.g. the `name` in `void greet(String name)`. An argument (or 'actual parameter') is the concrete value supplied at the call site that gets bound to that parameter, e.g. the `"Ada"` in `greet("Ada")`. The simple mnemonic: parameters are defined, arguments are passed. When the method is invoked, each argument is evaluated and its value is copied into the corresponding parameter (Java is strictly pass-by-value). The argument's type must be assignment-compatible with the parameter's declared type, and arguments are matched to parameters positionally, left to right.
go deeper
Correctly distinguishes the declared placeholder (parameter) from the passed value (argument).
Adds that arguments are evaluated and copied into parameters positionally, and ties this to pass-by-value.
Notes assignment compatibility, autoboxing/widening during binding, and that reference values are copied so the object is shared but the variable is not.
Uses precise terminology when reasoning about overload resolution and API ergonomics, and can articulate why Java's lack of named arguments shapes builder/parameter-object patterns.
## The two terms - A **parameter** (formal parameter) is the variable in the method *declaration*. It is a local variable, valid only inside the method body, that names an input. In `int add(int x, int y)`, `x` and `y` are parameters. - An **argument** (actual parameter) is the value supplied at the *call site*. In `add(3, total)`, `3` and `total` are arguments. ## Mnemonic *Parameters are in the **P**rototype/declaration; **A**rguments are what you **A**ctually pass.* Or: "you *define* parameters, you *pass* arguments." ## How they connect at a call When you invoke a method: 1. Each argument expression is **evaluated** (left to right). 2. Its resulting **value is copied** into the matching parameter variable (Java is always *pass-by-value* — for object references the *reference value* is copied, not the object). 3. The parameters are positionally bound: the first argument fills the first parameter, and so on. Java has no named-argument calls. 4. Each argument must be **assignment-compatible** with its parameter's type (with the usual widening conversions, autoboxing, and varargs handling applied during overload resolution). ## Why the distinction is worth keeping straight - It clarifies discussions of pass-by-value: 'the argument's value is copied into the parameter' is the precise phrasing. - It avoids confusion in overload-resolution talk ('the arguments determine which overload's parameters match'). - It matters in tooling/specs: the JLS and Javadoc use the terms precisely. ## A worked example ```java static double areaOfCircle(double radius) { // radius = parameter return Math.PI * radius * radius; } double a = areaOfCircle(2.5); // 2.5 = argument ``` Inside the method, `radius` holds a *copy* of `2.5`. Reassigning `radius` would not affect anything at the call site, because only the value was passed.
- If you reassign a parameter inside the method, does the caller's argument change?No. The argument's value was copied into the parameter, so reassigning the parameter only changes the local copy. (For object arguments you can still mutate the shared object via the copied reference, but you cannot reseat the caller's variable.)
saying these in an interview costs you the question
- Using the terms interchangeably in a way that confuses the listener
- Claiming Java has named arguments (it does not)
- Saying the parameter is what you pass at the call