

Passing by Value (Object References).
In an earlier video, I discussed a common difficulty that every beginner Java programmer encounters – does Java pass primitive data variables (i.e. int, float, char, boolean, etc) to method parameters by value or by reference. Recall Java *always* passes by value (passes a copy) and never by reference (passes the original).
In this video, I explain using examples how Java passes object references by value (that is to say – passes a copy of the object variables, arrays, etc) . In particular, I illustrate in detail how the passing by value of object references can exhibit behavior that is very similar to passing by reference (i.e. passing the original object memory address).
I hope you find this video beneficial. Please leave any comments or feedback in the comments section and I will respond as soon as I can. Thank you.
WATCH SOME MORE JAVA TUTORIALS
Enhanced For Loop Explained and Illustrated
For Loops Explained and Common Pitfalls Highlighted
How to use the Shortcut Operators
How to use the Conditional Operator ( ? : )
Compare Objects – Equality Operator Vs Equals Method
Command Line Arguments
How To Write A Method Part II
How To Write A Method Part I
Passing by Value (Primitive Data Types)
Division and Modulo Operators Explained
Operator Precedence Explained
What are Data Types, Variables and Constants?
How to use Nested If Statements
How to use simple If Statements
What are Control Flow Statements
How to Write, compile and run your first Java program on Windows
How to write, compile and run Java programs all within Notepad++
How to download and install the Notepad++ editor on Windows
Thanks for clearing it up, You've done a better job at explaining this than all these other Java tutorials that somehow expect you to understand this stuff automatically.
Perfect explanation
Thank you
thank you!
I understood this. Now I am confused… why for primitive types it doesn't work like that. Meaning, "int person1" having an address "1234" does not make a copy into "int person2" having an address "1234", and both hold a value say 111.
I really hope u read this…" R u an angel or what"…
We can see that u don't get that much of views and sub…But for people…Only if u could pls keep making such videos..Thanks..
It was amazing thank you for your help.
you have successfully explained what is called passing by reference for decades and then you name it passing by value.
Java is passing by sharing "Thus the behaviour of call by value Java or Visual Basic and call by value C or Pascal are significantly different: in C or Pascal, calling a function with a large structure as an argument will cause the entire structure to be copied and mutations to the structure are invisible to the caller. However, in Java or Visual Basic only the reference to the structure is copied and mutations to the structure are visible to the caller."
Thank you very much.
wow at last I got it. here it is: when passing object types you are not passing the data of the object but the address of the object. so you are passing a copy of the reference address of the object.
thank you for this tutorial!
This is confusing, when talking about passing by value it should always refer to parameters and yes the value is copied from the argument of the caller method into the parameter of the called method. I don't think you should refer to assigning variable person2 the address(you call it value) contained in variable person1 that points to object (John,21) as pass by value.
Thanks ,
Just,Could you tell about a book for java SE to read ?
Wowwww! Such an amazing explanations. This video has blown my brain! You are incrediable teacher. I wish you could make videos on Java. Thanks
I finally understood without getting confused what this is about. Thank you so much for this.
How is passing by the "value of a reference" considered to be passing by value, instead of passing by reference? It seems to me that this IS passing by reference. Wouldn't passing by value mean to copy the data state of person1 to person2 at that point in the program, so that they are two different objects and would reflect different data when manipulated differently?
I mean I understand what is happening, I just don't get why copying memory addresses doesn't qualify as a pass by reference when the memory address is what is used to reference an object.
That visual makes it so much easier to learn!!
Sir what is 123.. is it the memory adress of the object john
Sir, i have a question.
Did the person1 and person2 store in the Stack memory and the values of them are the address refer to the same Object store in the Heap memory?
Great tutorial…Just speak a bit slower next time, please… 🙂
This is a great, great tutorial and explains what it should in the best possible way. It is a shame that you have only couple of tutorials about java and not much more because you could be one of the best java lecturer. Thanks for making this video and of course like, share, subscribe…
Great explanation…
bro why is your mic in your throat
woow its realy helpfull
Well explained. Thanks nigga.
thank sir !
That was really helpful! Thanks
Excellent tutorial and the explanation is great!
Notepad++ FTW!!!
Niecely done!
Brilliant vid, thanks Martin!
Thanks for the awesome tutorial
you have explained it in best possible way. thanks 🙂
But where does focus fit into the program? I notice programmer used it a lot.
I wanna hug you right now.
Very good explained! Thx!