Java Parameter Passing
Mechanisms
Call by Value
• Definition: A copy of the actual parameter is
passed to the method.
• Effect: Changes to parameters inside the
method do not affect original variables.
• Java Support: ✅ Yes
• Example:
• public void change(int x) {
• x = 5;
• }
Call by Reference
• Definition: The method receives a reference to
the actual parameter.
• Effect: Changes inside the method affect the
original variable.
• Java Support: ❌ No (Not directly supported)
• Simulation: Java allows object state
modification but not reassigning reference.
• Example:
• public void modify(Person p) {
Call by Value-Result
• Definition: A copy is passed in, and after
execution, result is copied back to caller.
• Effect: Original variable can be updated after
the method.
• Java Support: ❌ No
• Languages: Found in Ada, early Pascal.
• Example: Not applicable in Java.
Call by Name
• Definition: Expression is passed unevaluated
and evaluated on use.
• Effect: Similar to lazy evaluation.
• Java Support: ❌ No (Simulated via lambdas)
• Simulation Example:
• printTwice(() -> Math.random());
• Used In: Algol, Scala (with lazy evaluation).
Summary Table
• Mechanism | Exists in Java | Description
• --------------------|----------------|-------------
• Call by Value | ✅ Yes | Java always
passes a copy of the value.
• Call by Reference | ❌ No | Not
supported. Object references are not
reassignable.
• Call by Value-Result| ❌ No | No copy-
back to original.
• Call by Name | ❌ No (simulated)|
Key Takeaways
• Java uses Call by Value exclusively.
• Objects in Java are passed as references by
value.
• Changes to object properties are visible
outside the method.
• True Call by Reference, Value-Result, and Call
by Name are not natively supported.
Thank You!