KEMBAR78
Java Parameter Passing | PDF
0% found this document useful (0 votes)
14 views8 pages

Java Parameter Passing

Java primarily uses Call by Value for parameter passing, where a copy of the actual parameter is sent to methods, preventing changes from affecting the original variable. Call by Reference, Call by Value-Result, and Call by Name are not natively supported in Java, though object state modifications can occur. Key takeaways include that while Java passes object references by value, true reassignments and certain other mechanisms are not available.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

Java Parameter Passing

Java primarily uses Call by Value for parameter passing, where a copy of the actual parameter is sent to methods, preventing changes from affecting the original variable. Call by Reference, Call by Value-Result, and Call by Name are not natively supported in Java, though object state modifications can occur. Key takeaways include that while Java passes object references by value, true reassignments and certain other mechanisms are not available.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

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!

You might also like