Method Parameters & Return Types in Java
Parameters are the named inputs a method declares in its signature — each has its own type, and calling the method must supply an argument matching that type for every parameter, in order. A method's return type declares what kind of value it hands back to its caller; void means it hands back nothing at all, and any other type requires every code path through the method to end in a return statement carrying a value of that type.
Java passes arguments by value. For a primitive, that means the method receives a copy of the number itself, so reassigning the parameter inside the method never affects the caller's original variable. For an object reference, the method receives a copy of the reference, still pointing to the same object — so mutating that object's fields is visible to the caller, but reassigning the parameter to point at a different object is not.
Declaring parameters
Each parameter in a method's signature has its own type and name, listed in the order arguments must be supplied.
Declaring a return type
void means the method returns nothing; any other type requires every path through the method to return a matching value.
Passing primitives by value
The method receives a copy of a primitive argument, so changes to the parameter inside the method never affect the caller's original variable.
Passing objects by value, too
The reference itself is copied, not the object, so mutating the object's fields is visible outside, but reassigning the parameter to a new object is not.
Multiple parameters, one call
Arguments are matched to parameters by position, not by name, so order matters.
public class ParamsDemo { static int square(int n) { n = n * n; return n; } public static void main(String[] args) { int original = 5; int result = square(original); System.out.println("Original: " + original); System.out.println("Result: " + result); }}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Java yourself — building beats watching.