In ICSE Java, Call by Value passes a copy of a primitive argument to a method, leaving the original variable unchanged in the caller. Passing an array or object passes a copy of its memory reference—commonly termed Call by Reference in CISCE textbooks—allowing the method to mutate shared elements or fields directly. Pure methods read arguments without altering caller state, whereas impure methods modify passed objects or array elements permanently.
- 1. How Primitive Arguments Behave Under Call by Value
- 2. Array and Object Mutations (ICSE Call by Reference)
- 3. Pure vs. Impure Methods in Section A Board Questions
- 4. ParameterPassingDemo.java (Call by Value vs Array Reference Mutation)
- 5. CISCE Variable Description Table (VDT) & Dry Run
- 6. Common Mistakes & Top Scorer Tips
- 7. Interactive Concept Check Quiz
- 8. Frequently Asked Questions
1. How Primitive Arguments Behave Under Call by Value
When you invoke a method with an int, double, or char argument, the Java Virtual Machine allocates a separate stack frame and copies the raw value into the formal parameter. Any arithmetic reassignment—such as x = x + 50—updates only that local formal copy inside the called method. Once the method returns, its stack frame is popped and discarded, so the actual parameter in main() retains its original value. CISCE Section A frequently tests this by naming the formal and actual parameters identically, tricking unprepared students into thinking both variables share one memory slot.
- Actual parameters belong to the caller's stack frame; formal parameters belong to the called method's frame.
- Swapping two primitive int variables inside a void swap(int a, int b) helper leaves the caller's variables unswapped.
- To persist a primitive change, return the updated value and assign it back in main().
2. Array and Object Mutations (ICSE Call by Reference)
Passing an array or class object behaves differently because the variable itself holds a heap memory address rather than raw data. Copying that reference into a formal parameter gives both main() and the helper method access to the exact same heap array or object fields. Consequently, writing arr[0] = arr[0] + 10 inside an impure method alters the original array visible back in main(). However, reassigning the reference itself inside the method (arr = new int[3];) only redirects the local parameter and leaves the caller's original reference untouched.
- Arrays and mutable user-defined objects allow element or field mutations to persist after the method returns.
- String objects are immutable; modifying a String parameter inside a method creates a new local String without changing the caller's reference.
- Use array-based swaps such as swap(int[] arr, int i, int j) when sorting methods must mutate data in place.
3. Pure vs. Impure Methods in Section A Board Questions
CISCE syllabi connect parameter passing directly to pure and impure functions. A pure method receives arguments, computes a result without changing any passed object or instance field, and returns a value—making it ideal for Call by Value primitives. Conversely, an impure (mutator) method modifies the state of a passed array or object in place and often uses a void return type. On two-mark definition questions, always state both the parameter copy rule and an authentic Java example pair such as Math.sqrt(n) versus an array-sorting helper.
- Pure methods produce zero side effects and always return the same output for identical inputs.
- Impure methods alter instance variables, static variables, or passed array/object contents.
- In 2-mark ICSE comparisons, contrast 'copy of data vs. reference address' and 'primitives vs. arrays/objects'.
4. ParameterPassingDemo.java (Call by Value vs Array Reference Mutation)
import java.util.*;
public class ParameterPassingDemo {
// Pure method: Call by Value on primitive int
public static void addBonusValue(int bonus) {
bonus = bonus + 500;
System.out.println("Inside addBonusValue (formal copy): " + bonus);
}
// Impure method: Reference copy mutates caller's array
public static void addGraceMarks(int[] marks, int grace) {
for (int i = 0; i < marks.length; i++) {
marks[i] = marks[i] + grace;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter initial bonus (primitive): ");
int bonus = sc.nextInt();
int[] marks = new int[3];
System.out.print("Enter 3 subject marks: ");
for (int i = 0; i < marks.length; i++) {
marks[i] = sc.nextInt();
}
addBonusValue(bonus);
System.out.println("In main after Call by Value: " + bonus);
addGraceMarks(marks, 5);
System.out.print("In main after array reference mutation: ");
for (int i = 0; i < marks.length; i++) {
System.out.print(marks[i] + (i < marks.length - 1 ? ", " : "\n"));
}
}
}
Verified Console / Dry-Run Output:
Enter initial bonus (primitive): 1000
Enter 3 subject marks: 78 84 91
Inside addBonusValue (formal copy): 1500
In main after Call by Value: 1000
In main after array reference mutation: 83, 89, 96
5. CISCE Variable Description Table (VDT) & Dry Run
| Variable | Data Type | Exam Purpose & Sample Value |
|---|---|---|
| bonus | int | Primitive passed by value; stays 1000 in main while formal copy becomes 1500 |
| marks | int[] | Array reference passed to method; mutates [78, 84, 91] into [83, 89, 96] |
| grace | int | Fixed increment added to every element inside addGraceMarks; sample: 5 |
| i | int | Loop counter iterating 0 to 2 over marks array |
| sc | Scanner | Reads primitive bonus and 3 array marks from System.in |
Trace Java Memory & Methods Without Guesswork
Walk through stack vs. heap memory diagrams and Section A output-tracing traps with an expert ICSE Java tutor in a 1-on-1 session.
6. Common Mistakes & Top Scorer Tips
- Avoid Mistake: Assuming that matching formal and actual parameter names (such as bonus in both main and helper) cause changes to reflect back in main().
- Avoid Mistake: Claiming Call by Reference changes a String argument in Java; Strings are immutable, so reassigning s = "New" only points the local parameter to a new String object.
- Avoid Mistake: Expecting arr = new int[3]; inside a method to replace the caller's array reference, instead of mutating elements via arr[i].
- Examiner / Mentor Tip: In Section A dry-run tables, draw separate columns for main()'s variables and the method's formal parameters to avoid mixing values.
- Examiner / Mentor Tip: When asked to define Call by Reference in an ICSE paper, explicitly mention arrays or objects as the parameter type.
- Examiner / Mentor Tip: Remember that Math library functions (Math.pow, Math.abs) are classic board examples of pure methods.
7. Interactive Concept Check Quiz
Question: Given void modify(int x, int[] a) { x = x * 2; a[0] = a[0] + 5; }, if main() calls modify(x, arr) with x = 10 and arr[0] = 4, what are x and arr[0] afterward in main()?
8. Frequently Asked Questions
Does Java truly support Call by Reference like C++ pointers?
If formal and actual parameters have the same name, does Call by Value change the original?
What distinguishes a pure method from an impure method in ICSE Class 10?
Explore Related Lessons & Free Interactive Tools
- All 110 Guides in ICSE Java BlueJ Library
- Java Wrapper Classes: Character & Integer Methods for ICSE
- Fixing Scanner nextLine() Buffer Skip vs. BufferedReader in Java
- Java ++x & x++ Precedence: ICSE Board Output Tracing
- Interactive Tool: ICSE Class 10 Java BlueJ Output Quiz
- Interactive Tool: ICSE Variable Description Table (VDT) Auto-Formatter
