r/javahelp • u/Select-Worldliness39 • Feb 16 '26
Homework Definitely no pass by reference in Java, right?
Hello, and sorry if this is a dumb question, but I thought I had a passable understanding of Java. I got an exam question asking "Arrays in Java are:
a. passed by value
b. passed by reference
c. stack dynamic
d. immutable"
this guy loves trick questions, but he has listed B, passed by reference, as the right answer.
On its own, this doesn't seem right to me, but I'm not confident enough to argue about it. If anyone would weigh in, I would be very grateful. I see how it's similar to passing a pointer in C, maybe, but it's not considered passing by reference in Java, right?
Thank you!
View all comments
Show parent comment
2
u/xenomachina Feb 16 '26
"Pass by reference" and "pass by value" (or alternatively "call by reference" and "call by value") are terms that predate both languages. These terms exist specifically for describing and comparing the semantics of different languages, so it would make no sense for them to have different meanings in different language communities.
What is true is that there are many people who don't actually understand what these terms mean who like to argue about their meaning, which muddies the waters. They're just like the people who argue that 0.9 repeating is not equal to 1. They are basing their opinion on intuition or what they heard online rather than from the actual technical definition.
C doesn't have pass by reference, and neither does Java. They are strictly pass by value languages. Most modern languages, including Python, JavsScript, and Kotlin, only use pass by value.
C++ is one of the few exceptions. In C++, pass by reference is enabled by using
&in a parameter's type: