Java Tutorial – Passing by Value (Object References)

///Java Tutorial – Passing by Value (Object References)

Java Tutorial – Passing by Value (Object References)

FavoriteLoadingAdd to favorites

Passing by Value (Object References).

Java468x60

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

source

By |2020-05-11T03:24:04+00:00May 11th, 2020|Java Video Tutorials|36 Comments

36 Comments

  1. winstons mother May 11, 2020 at 3:24 am - Reply

    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.

  2. C A May 11, 2020 at 3:24 am - Reply

    Perfect explanation

  3. Mohammad Sulaiman May 11, 2020 at 3:24 am - Reply

    Thank you

  4. Simoo 77 May 11, 2020 at 3:24 am - Reply

    thank you!

  5. Bishwas Mishra May 11, 2020 at 3:24 am - Reply

    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.

  6. Ankit Saini May 11, 2020 at 3:24 am - Reply

    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..

  7. Mouadrim Wind May 11, 2020 at 3:24 am - Reply

    It was amazing thank you for your help.

  8. Martin ISDN May 11, 2020 at 3:24 am - Reply

    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."

  9. Faris Mizan May 11, 2020 at 3:24 am - Reply

    Thank you very much.

  10. Arnold Dhara May 11, 2020 at 3:24 am - Reply

    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.

  11. Yabo Detchou May 11, 2020 at 3:24 am - Reply

    thank you for this tutorial!

  12. Georgiana Dan May 11, 2020 at 3:24 am - Reply

    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.

  13. Ahmed ELMawrdy May 11, 2020 at 3:24 am - Reply

    Thanks ,
    Just,Could you tell about a book for java SE to read ?

  14. Sam May 11, 2020 at 3:24 am - Reply

    Wowwww! Such an amazing explanations. This video has blown my brain! You are incrediable teacher. I wish you could make videos on Java. Thanks

  15. joanne h May 11, 2020 at 3:24 am - Reply

    I finally understood without getting confused what this is about. Thank you so much for this.

  16. Derrick Lange May 11, 2020 at 3:24 am - Reply

    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.

  17. YouTube C May 11, 2020 at 3:24 am - Reply

    That visual makes it so much easier to learn!!

  18. Stephen Haokip May 11, 2020 at 3:24 am - Reply

    Sir what is 123.. is it the memory adress of the object john

  19. Ben Ben May 11, 2020 at 3:24 am - Reply

    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?

  20. Ivan Pantic May 11, 2020 at 3:24 am - Reply

    Great tutorial…Just speak a bit slower next time, please… 🙂

  21. Ivan Pantic May 11, 2020 at 3:24 am - Reply

    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…

  22. avinash kumar singh May 11, 2020 at 3:24 am - Reply

    Great explanation…

  23. sencho May 11, 2020 at 3:24 am - Reply

    bro why is your mic in your throat

  24. Hasara S Wijesinghe May 11, 2020 at 3:24 am - Reply

    woow its realy helpfull

  25. Hellrock May 11, 2020 at 3:24 am - Reply

    Well explained. Thanks nigga.

  26. Quyết Đỗ Văn May 11, 2020 at 3:24 am - Reply

    thank sir !

  27. Andy M May 11, 2020 at 3:24 am - Reply

    That was really helpful! Thanks

  28. Radu B. May 11, 2020 at 3:24 am - Reply

    Excellent tutorial and the explanation is great!

  29. Andrew T May 11, 2020 at 3:24 am - Reply

    Notepad++ FTW!!!

  30. GroovySalmon May 11, 2020 at 3:24 am - Reply

    Niecely done!

  31. Thomas May 11, 2020 at 3:24 am - Reply

    Brilliant vid, thanks Martin!

  32. Jubaer Hossain May 11, 2020 at 3:24 am - Reply

    Thanks for the awesome tutorial

  33. Jovita Lobo May 11, 2020 at 3:24 am - Reply

    you have explained it in best possible way. thanks 🙂

  34. Ne1 2bot May 11, 2020 at 3:24 am - Reply

    But where does focus fit into the program? I notice programmer used it a lot.

  35. Daniel Lopes May 11, 2020 at 3:24 am - Reply

    I wanna hug you right now.

  36. Mihai Marinescu May 11, 2020 at 3:24 am - Reply

    Very good explained! Thx!

Leave A Comment

*