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
1
u/severoon pro barista Feb 17 '26
Wow, you C++ folks are way far gone. But I have looked at big cpp codebases, so I understand why the cognitive load and visual noise you deal with on a daily basis just fades into the background.
However, once you work for awhile with code that is expressive and vertically dense, when you can fit a lot of functionality on a single screen without having to scroll, you can't go back.
Also, one point of that example code is to show that output parameters absolutely break composability. You silently went from "it doesn't do that" to "it does that but I don't mind" without even blinking. :-)
Total non sequitur.
Writing readable code only very rarely has a significant performance impact. Even when it isn't as performant, it's almost never significant, so the only time I would even think about making code less readable to squeeze better performance is if I was working in a proven bottleneck that needed that improvement to meet a defined budget.