I need a CS kind of explanation on how the following 2 methods work differently from each other. I do not have a CS background (studied accounting .. blaahh) so please elaborate where you think is necessary. So java is a pass by value language from what I've read.
Consider the below primitive method. What exactly is it going to do in the background? The bit equivalence of lets say int myvar =7;
will be made a copy of and passed into the method? How, please elaborate?
public void changePrim(int var){
var = 100;
System.out.println("in change prim:"+ var);
}
Next, the below method is going to have a variable passed into it that will be of type Person.
public void changePersonObject(Person p) {
p.setAge(100);
p.setFirstName("Lost");
p.setLastName("Boy");
// p = new Person("Lost", "Boy", 24, 100); // this creates new. why?
}
So the first primitive argument method didn't change the int variable that was passed in to it from the client. Why does the second butcher the Person object's first and last name? Please elaborate with some emphasis in Computer Science. I'm learning that in parallel along with how java works. So bits and bytes would be deliciously devoured. Thank you.