What is the difference between passing by value and passing by reference in Java?
In Java, there is no such transfer by reference; everything in Java is passed by Value!
Variables in Java are typed, the JVM needs to know which variables are variables before executing the program, and based on the type it will try to allocate memory to store the value stored in this variable.
Now there are primitive types and objects, primitives have a fixed size (for example, char, byte, int, long, etc.). objects can be something else that groups primitive variables and functions.
In other words, primitives are a variable that contains a value whose type is known and determined by size, and objects is a variable whose value is the memory address of an actual object that has a collection of variables and functions.
Thus, in the context of executing a function, primitives pass a copy of the actual value to the function, and objects pass a copy of the address to the address where the instance is stored, so the objects seem to pass a breakpoint where the actual Object is stored.
The key point is that Java never provides direct access to the values โโof the objects themselves under any circumstances. The only access to the specified object is through a link.
Sayali patil
source share