Java Tutorial - Passing by Value (Object References)

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ก.ค. 2024
  • 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
    • Java Tutorial - Enhanc...
    For Loops Explained and Common Pitfalls Highlighted
    • Java Tutorial - For Lo...
    How to use the Shortcut Operators
    • Java Tutorial - How to...
    How to use the Conditional Operator ( ? : )
    • Java Tutorial - How to...
    Compare Objects - Equality Operator Vs Equals Method
    • Java Tutorial - Compar...
    Command Line Arguments
    • Java Tutorial - Comman...
    How To Write A Method Part II
    • Java Tutorial - How To...
    How To Write A Method Part I
    • Java Tutorial - How To...
    Passing by Value (Primitive Data Types)
    • Java Tutorial - Passin...
    Division and Modulo Operators Explained
    • Java Tutorial - Divisi...
    Operator Precedence Explained
    • Java Tutorial - Opera...
    What are Data Types, Variables and Constants?
    • Java Tutorial - Introd...
    How to use Nested If Statements
    • Java Tutorial - How to...
    How to use simple If Statements
    • Java Tutorial - How to...
    What are Control Flow Statements
    • Java Tutorial - What a...
    How to Write, compile and run your first Java program on Windows
    • Java Tutorial - How to...
    How to write, compile and run Java programs all within Notepad++
    • Java Tutorial - How to...
    How to download and install the Notepad++ editor on Windows
    • How to download and in...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 231

  • @leiferrrikson4676
    @leiferrrikson4676 3 ปีที่แล้ว +5

    This 2015 video is better than a number of tutorials in 2021. Thx!!

  • @pratikpatil2646
    @pratikpatil2646 2 ปีที่แล้ว +1

    I have been banging my head to understand this for last hour but you explained it so simply. Now I understand why java is only said to have passing by value.

  • @itachiuchiha-vs3qb
    @itachiuchiha-vs3qb 6 ปีที่แล้ว +1

    this is the best video on youtube. if you can't understand it now, leave programming, leave earth, leave this universe.

  • @martinisdn541
    @martinisdn541 4 ปีที่แล้ว

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

  • @romannagel2414
    @romannagel2414 8 ปีที่แล้ว +19

    Excellent! I think this is the best explanation given for passing objects as parameters and passing those by value!

  • @akashkotabagi
    @akashkotabagi 7 ปีที่แล้ว

    Last 5 minutes of your video exactly explains why we get confused with pass by value and pass by reference in java while dealing with objects. Good job man! Thank you !

  • @Aditya-jv9mp
    @Aditya-jv9mp 3 ปีที่แล้ว +1

    Thank you so much!
    5 years later and still very helpful!

  • @rjjaiswal
    @rjjaiswal 8 ปีที่แล้ว +43

    Sir I really appreciate your effort. You made it look so easy. My concept is clear now.
    Thanks for making this video!!!

  • @ad5772
    @ad5772 4 ปีที่แล้ว +1

    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.

  • @deezeed2817
    @deezeed2817 4 ปีที่แล้ว

    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.

  • @yaguarete79
    @yaguarete79 8 ปีที่แล้ว

    At last somebody explains it plain and clear!. I read and read about this but never understood it quite clear. Now I realize I had the concept all the way round. Thank you!

  • @ivanpantic6701
    @ivanpantic6701 5 ปีที่แล้ว +5

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

  • @simiiv5021
    @simiiv5021 3 ปีที่แล้ว

    Best video on youtube to explain this concept!

  • @teeru1983
    @teeru1983 8 ปีที่แล้ว +1

    Simple and Clear explanation. Thank you!

  • @mattchana707
    @mattchana707 7 ปีที่แล้ว

    Martin you explained this so well, very much appreciated!!!

  • @joanneh9753
    @joanneh9753 5 ปีที่แล้ว

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

  • @RhoChalmers
    @RhoChalmers 2 ปีที่แล้ว

    Love this tutorial. It is helpful. I have ADHD, however, and there are just a few too many commercial breaks for me to focus. Luckily I can watch this several times and take notes.

  • @mikeweiss8453
    @mikeweiss8453 6 ปีที่แล้ว +1

    Such a good explanation of this. I was baffled before and now I'm confident I could explain this to someone new. Thanks a ton!

  • @dukkhan1288
    @dukkhan1288 7 ปีที่แล้ว +1

    Excellent explanation, thank you! If you're still making videos and want to expand, I think an in depth video explaining deep copying would be greatly appreciated.

  • @gregaikey1676
    @gregaikey1676 2 ปีที่แล้ว

    The explanation was clear and concise in the best possible way. Well done.

  • @youtubeaccount0x073
    @youtubeaccount0x073 5 ปีที่แล้ว +2

    That visual makes it so much easier to learn!!

  • @startgrowyouritcareer1363
    @startgrowyouritcareer1363 6 ปีที่แล้ว

    WoW. Thank soooooooooooooo much. Just learning Java, watched many videos but was more confused with Pass by value and Pass by reference. Your video is OUTSTANDING, CLEAR AND WELL EXPLAINED.

  • @dandubq
    @dandubq ปีที่แล้ว

    The best explanation on the internet, this is amazing. Thank you!

  • @nikhilpothuru1167
    @nikhilpothuru1167 7 ปีที่แล้ว

    You're a hero. I have a CS midterm tom. This was a great watch!

  • @shuntayedwards6974
    @shuntayedwards6974 2 ปีที่แล้ว +1

    This was the best explanation I have watched. Thank you for making this so simple

  • @senthoorran
    @senthoorran 8 ปีที่แล้ว +1

    This video is very easy to understand the concept. Thanks for this video

  • @TheMcallist1
    @TheMcallist1 6 ปีที่แล้ว

    Brilliant vid, thanks Martin!

  • @Affliction604
    @Affliction604 6 ปีที่แล้ว +2

    Did a great job in the Java interview i've had today thanks to you

  • @devansh_agarwal9851
    @devansh_agarwal9851 ปีที่แล้ว

    Amazing explanation! Appreciated!

  • @jovitalobo1273
    @jovitalobo1273 6 ปีที่แล้ว

    you have explained it in best possible way. thanks :-)

  • @apbh
    @apbh 8 ปีที่แล้ว

    Beautifully explained!

  • @radub6436
    @radub6436 5 ปีที่แล้ว

    Excellent tutorial and the explanation is great!

  • @FitLife6767
    @FitLife6767 8 ปีที่แล้ว +1

    Thank you very much from Brazil. ...very straightforward...

  • @constantincrintea8219
    @constantincrintea8219 ปีที่แล้ว

    Wow, you are asome, the best explanation I have ever seen, congratulations and thank you very much, finally after some time I understood how to pass an object in a method

  • @borisrunakov1662
    @borisrunakov1662 8 ปีที่แล้ว +1

    Such a great video ! I really appreciate it . Thank you !

  • @alwysrite
    @alwysrite 7 ปีที่แล้ว

    one of the better tutorials (have not seen a better one yet) on this topic.

  • @abrehamish
    @abrehamish ปีที่แล้ว

    You have made it clear for me. Thank you for your excellent and brief presentation.

  • @ThanhNguyen-qk2zb
    @ThanhNguyen-qk2zb 2 ปีที่แล้ว

    Very simple and clear explanation, thank you very much sir!

  • @ajm01010
    @ajm01010 5 ปีที่แล้ว +1

    That was really helpful! Thanks

  • @Suraj-pf6ic
    @Suraj-pf6ic 6 ปีที่แล้ว

    Great example. Thanks.

  • @aiuv1792
    @aiuv1792 8 ปีที่แล้ว +4

    Thank you. really clear. i don't why other post don't directly point out passing by value for object means passing address.

    • @MartinOConnorComputing
      @MartinOConnorComputing  8 ปีที่แล้ว +2

      +Yichen Lin
      Delighted that my videos could be of some help. :)

    • @noeldiaz1354
      @noeldiaz1354 5 ปีที่แล้ว

      Because it doesn't mean that. Passing by value means copying, it just happens that what you copy is the bits of the value of the reference in java. If it's a primitive data type these bits contain the value of the primitive data type itself

  • @ludwig7223
    @ludwig7223 ปีที่แล้ว

    Very clear explanation. Thank you!

  • @Mec387
    @Mec387 3 ปีที่แล้ว +1

    I love your videos. Please, can you make more videos on object references with more than 2 classes.

  • @johnjohnson5407
    @johnjohnson5407 6 ปีที่แล้ว

    Thanks so much for the explanation, very clear/descriptive and now I understand.

  • @bor3y2
    @bor3y2 8 ปีที่แล้ว +1

    thank you very very very much. now everything is cleared to me.

  • @petersonjr8015
    @petersonjr8015 3 ปีที่แล้ว

    Perfectly explained. Thanks very much.

  • @girips29testing
    @girips29testing 7 ปีที่แล้ว

    thanks...very simple & clear explanation...

  • @LawZist
    @LawZist 9 ปีที่แล้ว +2

    very good mate!! i got the idea for the first time .

  • @thestarinthesky_
    @thestarinthesky_ 5 ปีที่แล้ว

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

  • @samme4life
    @samme4life 3 ปีที่แล้ว

    Mate, you have explained it very clearly. Thank you

  • @rezashahbazi2679
    @rezashahbazi2679 3 ปีที่แล้ว

    The best explanation on this topic! Thanks

  • @FarhaJawedCSE_MIST
    @FarhaJawedCSE_MIST 7 ปีที่แล้ว

    Great explanation! I appreciate your effort.

  • @jubaer.hossain
    @jubaer.hossain 6 ปีที่แล้ว

    Thanks for the awesome tutorial

  • @Suraj-pf6ic
    @Suraj-pf6ic 6 ปีที่แล้ว

    Thanks for this tutorial. Very clear.

  • @scottwalton5932
    @scottwalton5932 8 ปีที่แล้ว +1

    Really good video thank you.

  • @mihaimarinescu9303
    @mihaimarinescu9303 6 ปีที่แล้ว

    Very good explained! Thx!

  • @AliPAioubi
    @AliPAioubi 7 ปีที่แล้ว

    Wow awesome explanation thank you

  • @avinashkumarsingh2007
    @avinashkumarsingh2007 5 ปีที่แล้ว

    Great explanation...

  • @LalGebi
    @LalGebi 7 ปีที่แล้ว

    Awesome.. your way of explaining.. concept cleared...

  • @DarthReVengeh
    @DarthReVengeh 2 ปีที่แล้ว

    素晴らしい!

    • @MartinOConnorComputing
      @MartinOConnorComputing  2 ปีที่แล้ว +1

      ありがとうございました (with the help of Google Translate) :)

  • @mohammedviso2269
    @mohammedviso2269 7 ปีที่แล้ว

    Very good explanation ....you helped me a lot

  • @muhammadsaad1850
    @muhammadsaad1850 8 ปีที่แล้ว

    thanks bro finally i understood it

  • @davyswanson7412
    @davyswanson7412 3 ปีที่แล้ว

    fantastic video and a great way of teaching, thanks for all the help

  • @alayah2734
    @alayah2734 2 ปีที่แล้ว

    Great explanation!

  • @markevans5648
    @markevans5648 4 ปีที่แล้ว

    Excellent job explaining this topic

  • @jingyang2016
    @jingyang2016 7 ปีที่แล้ว

    Good explaination, I think the reason it looks quiet like pass by reference is that changeDetails method is actually changing the memory

  • @simm5622
    @simm5622 2 ปีที่แล้ว

    Wow beautifully explained. 🏆🏆🏆🏆🏆

  • @whatarewetoday4585
    @whatarewetoday4585 2 ปีที่แล้ว

    This is great. Thank you so much

  • @ceanorme
    @ceanorme 8 ปีที่แล้ว +2

    Great explanation. Thanxs :-)

  • @mehmetfatiherdem7074
    @mehmetfatiherdem7074 3 ปีที่แล้ว

    Great explanation Sir!

  • @Waleed-hf9ic
    @Waleed-hf9ic 6 ปีที่แล้ว

    Thank you , now is clear to me.

  • @mouadrimwind8839
    @mouadrimwind8839 4 ปีที่แล้ว

    It was amazing thank you for your help.

  • @keithfjord
    @keithfjord 7 ปีที่แล้ว

    great explanation

  • @kokoreply
    @kokoreply 6 ปีที่แล้ว

    thank you! bless your heart

  • @Farsmezan
    @Farsmezan 4 ปีที่แล้ว

    Thank you very much.

  • @ca9888
    @ca9888 4 ปีที่แล้ว

    Perfect explanation

  • @FraztheWizard
    @FraztheWizard 3 ปีที่แล้ว

    Legend! Thankyou!

  • @simoo7755
    @simoo7755 4 ปีที่แล้ว +1

    thank you!

  • @groovysalmon6857
    @groovysalmon6857 6 ปีที่แล้ว

    Niecely done!

  • @VladMarinVlog
    @VladMarinVlog 3 ปีที่แล้ว

    Bless you man!

  • @kimsungho4114
    @kimsungho4114 2 ปีที่แล้ว

    Thank you sir, this helped a lot :)

  • @abhi_kl04
    @abhi_kl04 3 ปีที่แล้ว

    Excellent explanation

  • @shlomi5044
    @shlomi5044 7 ปีที่แล้ว

    thank you very much

  • @shaminmohammed6157
    @shaminmohammed6157 9 ปีที่แล้ว +1

    EXCELLENT- super

  • @srinidhiskanda754
    @srinidhiskanda754 8 ปีที่แล้ว +1

    thank you very much beautiful explanation. sir can you do tutorial about oop concepts and collections in java ?

  • @instaminox
    @instaminox 7 ปีที่แล้ว

    Interview question! thanks

  • @realreddog8866
    @realreddog8866 8 ปีที่แล้ว +1

    great video really enjoyed it, is it possible you could edit your videos with numbers and put them in order so i can go through them as though its like a step by step course? i find your way of teaching far better to understand than most other videos i have seen so would like to learn what java i can from you! thank you

  • @senjuakashi7733
    @senjuakashi7733 2 ปีที่แล้ว

    great tutorial.

  • @in5125
    @in5125 2 ปีที่แล้ว

    thank you very much!!!

  • @jomarbombita5078
    @jomarbombita5078 4 ปีที่แล้ว

    Well explained great sir😁😊

  • @worlanyoadom3548
    @worlanyoadom3548 3 ปีที่แล้ว

    Thank you Sir.

  • @kevinbenavides92
    @kevinbenavides92 6 ปีที่แล้ว

    Thank you sir!!

  • @tbschandra
    @tbschandra 3 ปีที่แล้ว

    Thanks for video

  • @vinhhong1428
    @vinhhong1428 5 ปีที่แล้ว

    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?

  • @andreas5077
    @andreas5077 7 ปีที่แล้ว

    thank you ,,

  • @hasaraswijesinghe9702
    @hasaraswijesinghe9702 5 ปีที่แล้ว

    woow its realy helpfull

  • @quyetdovan
    @quyetdovan 5 ปีที่แล้ว +1

    thank sir !

  • @emmioglukant
    @emmioglukant ปีที่แล้ว

    Excellent, you need to know C++ (specificly shared_ptr) to understand Java 'references'. Everything boils down to C and C++ I guess...

  • @niche9015
    @niche9015 5 ปีที่แล้ว +2

    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.

  • @mohammadsulaiman2301
    @mohammadsulaiman2301 4 ปีที่แล้ว

    Thank you