Method Parameters in Java: Parameters vs Arguments, Rules and Pass by Value
Difficulty: Beginner · Importance: High · Java version: Java 1.0+ (autoboxing: Java 5+) · Last updated: 31 Oct 2026
Output puzzle: What does this print?
If you said 35000, this lesson will save you from a very common bug.
Quick Answer
Method parameters in Java are the variables listed in a method’s declaration, like name in greet(String name). They receive input when the method is called. The values you pass in the call are arguments. Java matches arguments to parameters by position, checks their types at compile time, and always passes a copy of the value (pass by value).
Before you start: read Introduction to Methods in Java for how to declare and call a method.
What Are Method Parameters in Java?
A parameter is a local variable that a method declares in its parentheses. It gets its value from the caller each time the method runs.
Output:
Namaste, Asha!Namaste, Rahul!One method, two different results. Parameters make a method general: it works on whatever data it’s given instead of fixed values.
Parameters vs Arguments (Formal vs Actual Parameters)
| Parameter (formal parameter) | Argument (actual parameter) | |
|---|---|---|
| Where | In the method declaration | In the method call |
| What | A variable with a type and a name | A value or expression |
| Example | String name | "Asha" |
| Lifetime | Exists only while the method runs | Evaluated just before the call |
Real-life analogy: a printed form has blank fields labelled “Name” and “Age”; those are the parameters. What you write in the blanks is the argument.
Syntax: Single and Multiple Parameters
Separate parameters with commas. Each one needs its own type, even if the types repeat.
Output:
Keyboard x 2 = Rs 1799.0Mouse x 1 = Rs 349.0A method with no inputs simply has empty parentheses: static void printDivider().
How Arguments Are Matched to Parameters
Java matches arguments to parameters using three rules, all checked at compile time:
- Same number of arguments as parameters.
- Same order: the first argument goes to the first parameter, and so on.
- Compatible types: each argument must be the same type or safely convertible.
Why Does Argument Order Matter?
If the types differ, the compiler catches a wrong order. If the types are the same, it can’t, and you get a silent wrong answer:
Output:
Correct order: 90.0%Swapped order: 111.11111111111111%
Both calls compile. Only clear parameter names, and careful reading of them, protect you here.
Do the Caller’s Variable Names Matter?
No. Only position matters, never the names:
Output:
width = 7, height = 321The caller’s height (7) landed in the parameter called width, because it was passed first.
Type Rules: Widening, Autoboxing and Narrowing
An argument doesn’t have to be exactly the parameter’s type. Java allows conversions that can’t lose information:
Output:
double parameter got 87.0double parameter got 87.0
int parameter got 65
Integer parameter got 87
Passing 'A' to an int parameter prints 65, its character code. That’s a favourite output-prediction question.
Narrowing (for example, double → int) could lose data, so Java refuses it unless you cast explicitly:
Output:
Rs 29Rs 30A cast truncates: 29.99 becomes 29, not 30. Use Math.round when you mean rounding. More in Type Casting in Java.
How Parameters Work Internally: Java Is Always Pass by Value
Back to the puzzle from the top:
Output:
Inside addBonus: 35000Salary after bonus: 30000
When a method is called, the JVM creates a new stack frame for it. Each parameter is a local variable in that frame, initialised with a copy of the argument’s value. addBonus changed its own copy; main’s salary was never touched. Sharing the name salary makes no difference.
What About Arrays (Reference Types)?
For a reference type such as an array, the value that gets copied is the reference (the address of the object on the heap). So both variables point to the same array:
Output:
After addGraceMarks: [75, 90, 65]
Inside replaceArray: [0, 0, 0]After replaceArray: [75, 90, 65]
Primitive parameters get a copy of the number, so changes stay inside the method. Array parameters get a copy of the reference: changes to the array’s contents are visible to the caller, but pointing the parameter at a new array (scores = new int[...]) only changes the local copy.
Remember: Java is always pass by value. For objects and arrays, the value passed is the reference. Java is never “pass by reference”. The full story, with objects and
String, is in Pass by Value in Java. Arrays are covered properly in Introduction to Arrays.
Final Parameters in Java
Marking a parameter final stops the method from reassigning it:
Output:
900.0final blocks reassignment, not changes inside an object or array:
Output:
[50, 8]final parameters make intent clear and stop accidental reassignment. Many teams leave them out for brevity and rely on code review or IDE warnings instead.
Validating Parameters
A method shouldn’t trust its inputs blindly. Check them at the top and reject bad values early:
Output:
90.0Exception in thread "main" java.lang.IllegalArgumentException: total must be positive, got 0
at Validation.percentage(Validation.java:9)
at Validation.main(Validation.java:4)
Failing fast with a clear message beats silently returning Infinity. You’ll learn how to handle exceptions in Introduction to Exception Handling.
Does Java Support Default Parameter Values?
No. Java has no price(double amount, double tax = 18) syntax. The usual workaround is overloading: a shorter method that calls the full one with a default value:
Output:
1180.01050.0Details in Method Overloading in Java. To accept any number of arguments of one type, Java uses varargs (int... numbers), covered in Variable Arguments.
How Many Parameters Can a Java Method Have?
The JVM limits a method to 255 parameter slots. On JDK 25, a static method with 255 int parameters compiles, but 256 fail with error: too many parameters. long and double take two slots each (127 longs compile, 128 fail). For an instance method, the hidden this reference takes one slot, so only 254 ints fit. In practice, anything beyond 3–4 parameters is a design problem, not a limit problem.
Real-World Example: Loan EMI Calculator
Output:
Bike loan: EMI Rs 5565.12, total Rs 133563.00, interest Rs 13563.00Laptop loan: EMI Rs 7182.97, total Rs 86195.63, interest Rs 6195.63
Bad input: invalid loan details
The formula is EMI = P × r × (1+r)ⁿ / ((1+r)ⁿ − 1), with the monthly rate r and n months. Descriptive parameter names (annualRatePercent, months) document the units, so callers are less likely to pass years where months are expected. The validation guard runs before any maths.
Rules and Important Points
- Each parameter needs its own type:
(int a, int b), never(int a, b). - Arguments must match parameters in number, order and compatible type.
- Widening (
int→double,char→int) and autoboxing (int→Integer) are automatic; narrowing needs a cast. - Parameters are local variables of the method; their scope is the method body.
- A local variable can’t reuse a parameter’s name in the same method.
- Java is always pass by value; for arrays and objects, the reference is copied.
finalprevents reassigning a parameter, not changing an object’s contents.- Java has no default parameter values; use overloading.
Common Mistakes With Method Parameters
Mistake 1: Sharing One Type Across Parameters
SharedType.java:2: error:expected static int area(int length, breadth) {
^
1 error
Why: int a, b works for local variables, not for parameter lists.
Mistake 2: Wrong Number of Arguments
WrongCount.java:3: error: method printInvoiceLine in class WrongCount cannot be applied to given types;printInvoiceLine("Pen", 3);
^
required: String,int,double
found: String,int
reason: actual and formal argument lists differ in length
1 error
Why: the compiler lists exactly what it required and what it found. Read those two lines first.
Mistake 3: Arguments in the Wrong Order (Different Types)
Fix: follow the declared order:WrongOrderTypes.java:3: error: incompatible types: int cannot be converted to StringprintInvoiceLine(3, "Pen", 10.0);
^printInvoiceLine("Pen", 3, 10.0). With same-type parameters there’s no error (see the percentage example), so double-check those calls.
Mistake 4: Passing a double Where an int Is Expected
Narrowing.java:4: error: incompatible types: possible lossy conversion from double to intprintRupees(price);
Mistake 5: Expecting a Method to Change the Caller’s Primitive
Why: the method changed its own copy.
Return values are the next lesson: Method Return Types.
Mistake 6: Declaring a Local Variable With the Parameter’s Name
DuplicateName.java:7: error: variable number is already defined in method square(int)int number = 10;
^
1 error
Fix: choose a different name, or just use the parameter.
Mistake 7: Reassigning a final Parameter
FinalParam.java:7: error: final parameter price may not be assignedprice = price - price * percent / 100;
^
1 error
Fix: store the result in a new local variable (see FinalParamFixed above).
Primitive vs Array/Object Parameters
Primitive parameter (int, double, …) | Array/object parameter (int[], String, …) | |
|---|---|---|
| What is copied | The value itself | The reference (address) |
| Method changes the value/contents | Caller doesn’t see it | Caller does see content changes (if the object is mutable) |
| Method reassigns the parameter | Caller doesn’t see it | Caller doesn’t see it |
| Example | addBonus(salary) | addGraceMarks(marks, 5) |
String is a reference type but immutable, so a method can never change a caller’s String. You’ll see why in the Strings section.
Best Practices
- Use descriptive names with units:
annualRatePercent,months,weightKg, notr,n,w. - Keep parameter lists short (ideally 3–4 or fewer). Group related values; later you’ll use objects or records (Java 16+) for this.
- Avoid several same-type parameters in a row when you can, since swaps compile silently.
- Validate at the top of the method and fail fast with a clear message.
- Prefer returning a new value over trying to modify an input.
- Avoid boolean “flag” parameters like
print(report, true). Two clearly named methods read better. - Use
finalon parameters if your team’s style asks for it; never reassign parameters either way.
Interview Questions on Method Parameters
How to answer in an interview: “Is Java pass by value or pass by reference?”
“Java is always pass by value. For primitives, the method gets a copy of the value. For objects and arrays, it gets a copy of the reference, so it can change the object’s contents, but reassigning the parameter never affects the caller’s variable.”
Output-Prediction Questions
Q1.
Answer: 9. reset changed its own copy.
Q2.
Answer: 66. char widens to int, and ‘B’ is 66.
Q3.
Answer: 1. The first assignment changes the shared array; after a = new int[]{7}, a points elsewhere, so a[0] = 2 doesn’t touch data.
Conceptual Follow-Ups
- What are formal and actual parameters? Formal parameters are in the declaration; actual parameters (arguments) are in the call.
- Can we pass an
intto adoubleparameter? Yes, by widening. The reverse needs a cast. - Does Java support default parameters? No; use overloading, or a builder for many options.
- What does
finalon a parameter guarantee? Only that the parameter isn’t reassigned inside the method. - What’s the maximum number of parameters? 255 slots (long/double count as two;
thistakes one in instance methods).
More: Java Interview Questions for Freshers · Intermediate Questions
Practice Exercises
- Easy: Write
static double average(int a, int b, int c)and test it with (70, 80, 95). - Easy: Write
static void printTable(int number, int upTo)that prints the multiplication table ofnumberup toupTo. - Easy–Medium: Write
static double bmi(double weightKg, double heightM)with validation for values ≤ 0. - Medium: Write
static void doubleAll(int[] values)and prove (by printing inmain) that the caller’s array changed. - Medium: Write
static int addMarks(int marks, int bonus)that returns the new value, and use it to fix theaddBonuspuzzle.
Practise on ExamAdda Practice and run your code in the ExamAdda Compiler.
FAQs
1. What is the difference between parameters and arguments in Java?
Parameters are the variables declared in a method’s parentheses. Arguments are the actual values passed when the method is called. Arguments are copied into parameters by position.
2. Is Java pass by value or pass by reference?
Always pass by value. For primitives, the value is copied; for objects and arrays, the reference is copied, so content changes are visible but reassignment isn’t.
3. Can a Java method change the value of a variable passed to it?
Not for primitives: the method only changes its own copy. To get a new value back, return it and assign it in the caller.
4. Does Java support default parameter values?
No. Use method overloading: a shorter version that calls the full version with the default value.
5. What is a final parameter in Java?
A parameter marked final can’t be reassigned inside the method. If it refers to an array or object, the contents can still change.
6. How many parameters can a method have in Java?
Up to 255 parameter slots, where long and double use two slots and this uses one in instance methods. Good design keeps it to a handful.
7. Why do I get “method cannot be applied to given types”?
The arguments don’t match the parameter list in number or type. The error shows the “required” and “found” types so you can compare them.
Article Summary
- Parameters are the method’s declared inputs; arguments are the values you pass, matched by position and type.
- Widening and autoboxing happen automatically; narrowing needs an explicit cast.
- Java is always pass by value: primitives are copied, and arrays/objects pass a copy of the reference.
finalstops reassignment of a parameter; validation at the top stops bad input early.- Java has no default parameters (use overloading) and allows at most 255 parameter slots.
Next → Method Return Types in Java · ← Previous: Introduction to Methods
References: Oracle Java Tutorials: Passing Information to a Method · JLS §8.4.1: Formal Parameters · JVM Spec §4.3.3: Method Descriptors (255-slot limit)