Hacking Hunter

A Publication — Where bugs become blueprints. Designed for developers — clean UI, easy on the eyes, and straight to the point. Take a look at the publication and follow for more.

Member-only story

Featured

Is Java PASS-BY-REFERENCE?

Primitives → Passed by value (copy of the value). Objects → Passed by value (copy of the reference)

4 min readMar 28, 2025

--

Photo by freestocks on Unsplash

What is Pass-by-Reference?

  • You send a reference (memory address) to the method.
  • If the method changes the value, it modifies the original variable.

c++ code

#include <iostream>
using namespace std;

void modifyNumber(int &x) { // x is passed by reference.
x = 10; // Changes original value
}

int main() {
int a = 5;
modifyNumber(a);
cout << a << endl; // Output: 10
return 0;
}

What is Pass-by-Value?

  • Pass-by-value means Java sends a copy of the value to a method.
  • If you change the value inside the method, the original value doesn’t change.

python code

x =5 

def modifyNumber(x):
x = 10

modifyNumber(x)
print(x) # x = 5

Non Medium Member Alert!!!
If you block by medium pay wall, You can read it with this link.
Dear Folks, Your 50 claps 👏👏 help the discussion [article] reach more developers 👀 on Medium, and your comments 💬 make me to keep writing. If you found this article helpful, consider supporting my writing with a

--

--

Hacking Hunter
Hacking Hunter

Published in Hacking Hunter

A Publication — Where bugs become blueprints. Designed for developers — clean UI, easy on the eyes, and straight to the point. Take a look at the publication and follow for more.

Sivaram Rasathurai
Sivaram Rasathurai

Written by Sivaram Rasathurai

ATL @Sysco | Architect of Oh Taxi App | 3.6M+ Impressions & 6K+ SO Reps with 100+ java and 100+ python Tips : https://buymeacoffee.com/rcvaram

Responses (2)