After choosing the correct answer, i wanna to said that In Java, primitive types are passed by value and stored in the stack (for local variables). Since the Collections API only works with objects, it uses wrapper classes like Integer or Double instead of primitives. However, it's important to note that even with wrapper classes, Java still passes object references by value. So while you can modify the state of a mutable object within a method (like modifying a List), you cannot change the reference or the value of an immutable wrapper like Integer from outside.
2 months ago | 6
In the book "Head First Java" there is a excellent explanation with TV Remote. You have One TV (object) and you have remote which is a variable point to the reference(tv). So "pass-by-value" methodName(tvObject) java will create a new remote which points to the TV, so you have two remote for one tv, and if you press turn off button on some of the remotes TV will be turned off. But if you assign a new object inside method that newly created remote will point to the new TV, so inside method you will have remote2 -> tv2 and outside remote1->tv1 So now it does matter where you press turn off button if you pres on remote2 only tv2 will be turned off
2 months ago | 0
But java is pass by reference only It doesn't support pass by value i think
2 months ago | 0
Amigoscode
1. What does it mean when we say Java is 'pass-by-value'?
2 months ago | [YT] | 87