.equals() vs. == in Java - The Real Difference

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ม.ค. 2021
  • Complete Java course: codingwithjohn.thinkific.com/...
    Watch now to learn the difference between ".equals()" vs. "==" in Java. Full tutorial on the difference between "==" (double equals) and the ".equals()" method in Java. Especially for Strings, when do you use ==, and when do you use .equals?
    Simple equality checks in Java can be tricky, but the facts are simpler than you may think.
    This is a very beginner friendly beginner's Java coding lesson tutorial, where we'll discuss the difference between == and .equals() when doing equals checks in Java.
    Learn or improve your Java by watching it being coded live!
    Hey, I'm John! I'm a Lead Java Software Engineer who has been in the industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java developers.
    Let me know what else you'd like to see!
    Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
    📕 THE best book to learn Java, Effective Java by Joshua Bloch
    amzn.to/36AfdUu
    📕 One of my favorite programming books, Clean Code by Robert Martin
    amzn.to/3GTPVhf
    🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
    www.audibletrial.com/johnclean...
    🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
    bit.ly/3QPNGko
    📹Phone I use for recording:
    amzn.to/3HepYJu
    🎙️Microphone I use (classy, I know):
    amzn.to/3AYGdbz
    Donate with PayPal (Thank you so much!)
    www.paypal.com/donate/?hosted...
    ☕Complete Java course:
    codingwithjohn.thinkific.com/...
    codingwithjohn.com
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @rykageee
    @rykageee 3 ปีที่แล้ว +131

    so far I've watched several videos with the same topic but this video only explained well. Thanks man!

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

      Awesome! Very glad I was able to help!

  • @Daresigmally
    @Daresigmally ปีที่แล้ว +23

    Oh my god I'm genuinely so thankful I discovered this Channel, John explains stuff like no one else does, you just earned yourself a subscriber mate, thank you for all the efforts.❤

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

    Feeling lucky to have found this channel, I've been self studying on and off for a couple years and I'm pretty sure I should have known these key concepts by now, sincere thanks for these clear and understandable teachings!

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

    OMFG please keep your content comming...im having a blast learning from you man. Im deeply grateful for all your lessons.

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

    Really fascinated at how good you are able to explain. Thanks for the great video!

  • @Visionist
    @Visionist 3 ปีที่แล้ว +16

    Simple and easy to understand. Thank you!

  • @olivierbegassat851
    @olivierbegassat851 9 หลายเดือนก่อน +2

    These are beautiful videos man 😁 Every sentence of yours resolves an issue I had and leads to the next question I had. So helpful ! Thanks 🙂

  • @magicalhats
    @magicalhats 2 ปีที่แล้ว +10

    I'm a newbie dev and I finished a bootcamp but your videos topics are all the topics I found confusing during class and always wondered about. TY so much.

    • @techexpert5600
      @techexpert5600 หลายเดือนก่อน

      go away bootcamp people

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

    Hi John you did very well in this lesson. I tried to learn .equals and == from a professor but I couldn't understand it and now I got the point from you in 5 minutes.

  • @terrypark3690
    @terrypark3690 6 หลายเดือนก่อน

    wow this goes well with your string pool video. Thanks for making these really comprehensive videos on how java works for the basic things we just usually use without thinking about.

  • @praveens9233
    @praveens9233 ปีที่แล้ว +17

    Warning ⚠️ : If you are going to override .equals method,you have to override your hascode method. Otherwise there will be a mess with those objects whenever you hashing

  • @ovey2214
    @ovey2214 2 ปีที่แล้ว +7

    That was incredibly well explained! Thanks a lot!

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

    I just found your channel and the world just makes so much more sense now.

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

    Had been scratching my head on a case similar to the example at last, luckily this video explained it. Huge thanks :)

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

    Thanks John, your tutorials are very helpful. You are a great teacher, hats off!

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

    tus videos tienen un gran valor, muchas gracias por compartir tu conocimiento

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

    this channel always dropping gems. Respect.

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

    This actually helped me understand why some of the code I was writing was initially breaking. Ty!

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

    I got back into Java recently after not using it for like 8 years and have been haphazardly using == for strings and it has been working, presumably because I have been always using strings as state variables in games, and so have been manually typing the strings in my conditions as literals (if (facing == "up")) etc.
    I saw a comment on another video and I'm glad I found this early enough to refactor everything. haha.

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

    Ah Lord! can't just say how easy you explained it. I have been really confused for several days about this simple .equals in object class and now I know how java processes it. Thank you so much for this video. Subscribed liked and commented. Keep up with your good work!!!!

  • @cananozdemir8913
    @cananozdemir8913 4 หลายเดือนก่อน

    I just bought his full Java course. Amazing explanation .

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

    Thanks for the video john seems like refreshing my basics

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

    Very well explained Jonh, Thanks again ♥

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

    Great video as always. Thank you for your dedication!

  • @dhavewala
    @dhavewala 2 ปีที่แล้ว +20

    John, this was an amazing tutorial!
    I had a query though; on the objects, do we override the equals() or is it inferred?

  • @harlockgaming1476
    @harlockgaming1476 6 หลายเดือนก่อน

    Love the Kramer picture in the back, my grandpa has one just like it! Thanks for the amazing videos!

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

    Thanks John, your tutorials are awesome.

  • @colonelh.s.l.3834
    @colonelh.s.l.3834 ปีที่แล้ว +1

    This is awesome! Can you do a video on priority queues and comparators, and how they come together?

  • @eshwarnag
    @eshwarnag 6 หลายเดือนก่อน

    the last part was really good!

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

    Thansk's John. Please don't stop your videos they are awesome

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

    Thanks so much for the video. Genuinely looking forward to the "how to write a good equals method" vid!

  • @shama-_-
    @shama-_- ปีที่แล้ว

    thanks a lot you help me to understand the concepts

  • @ruzi173
    @ruzi173 8 หลายเดือนก่อน

    This is just the best explanation..wow👏Thank you for all your videos🙏

  • @ujjwals.dadwal8911
    @ujjwals.dadwal8911 2 ปีที่แล้ว

    Thanks John, Mucha Gracias from Canada!

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

    Easy to understand. Thank you.

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

    This guy is the best as a learner and teacher guide

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

    Love your videos bro. Very helpful. Thanks a lot

  • @InfiniteWisdom1.0
    @InfiniteWisdom1.0 6 หลายเดือนก่อน

    Thank you so much, your videos are pretty helpful 😊

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

    Very clear. Awesome examples and also my eyes love the dark theme ^^

  • @user-dm8tm2pm9o
    @user-dm8tm2pm9o 8 หลายเดือนก่อน

    Thx for your clear presentation Sir

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

    Great lessons as usual. Thanks.

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

    This is the best i have understoon so far...

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

    I wish you were my lecturer at Uni. You have talent man!

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

    By the beard of Zeus! Your contributions to the world of programming are nothing short of epic. Your Java beginner's playlist is truly a stroke of genius, and I speak for many when I say, you are the real MVP!

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

    Thank you so much.. Your explanation is very clear...!!!

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

    Wow, noob here, didnt know those details till you explain it, massive thanks John!

  • @anjelomanoranjan
    @anjelomanoranjan 8 หลายเดือนก่อน

    Thanks! Your videos are great!

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

    wow, very well explained. Thank you

  • @robertod893
    @robertod893 9 หลายเดือนก่อน

    Excellent video as always!

  • @lamaspacos
    @lamaspacos 2 หลายเดือนก่อน

    This channel is very very good.

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

    Wow thanks man it is so well explain !

  • @brtkgromek
    @brtkgromek 2 ปีที่แล้ว +3

    I'm glad I've found this chanel. I've never been more educated by any other escaped convict in my entire life! Keep it up! :)

  • @YusufDemir-gx7he
    @YusufDemir-gx7he 2 ปีที่แล้ว

    It seems I've found my coding channel. Thanks for the video :)

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

    thank you, sir. !! great explanation.

  • @konstantinzakharov5643
    @konstantinzakharov5643 10 หลายเดือนก่อน

    I love this guy! I am hitting the Like button!

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

    Good explanation! What about enum comparation? What should I use?

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

    Very interesting ,thank you .

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

    Might also be worth mentioning that you can use == with enum's as well.

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

    Amazing explanation, thanks alot

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

    thank you so much! very helpful!

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

    Just the greatest explanation !

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

    thanks a lot !!! awesome explanation

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

    Thanks John!

  • @akna1987
    @akna1987 3 หลายเดือนก่อน

    These videos are great! But you should have included a video on how to implement the .equals-method and compare-to method to your own class

  • @GenjaOrigins
    @GenjaOrigins 2 ปีที่แล้ว +3

    You are great. Congrats for channel and being Team Leader. Maybe you could/should make a video talking about what should a junior know. I think i know equals now, exceptions/throw/finally/catch etc, im learning generics and i undertand but i saw a generic method in an interview(company was about HR, and i was asked 4 Design Patterns which i knew but wasnt good enough for company anyway) i had no idea what it was even if i knew generics it was kind of pro code/ultra weird and hard i think it was with lists btw..i also hate leetcode i prefer videos like yours to actually learn java. I would also learn more from you cause you good and you enjoyable i hope you do the same in your job irl. i think i also know most of collections hashmap/set etc

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

    John, where did you get the source and how did you attach the source to the binaries? UPDATE: solution is to point your JRE path to the path with the JDK instead!

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

    Nice job John !

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

    Amazing tutorial!

  • @HR-pz7ts
    @HR-pz7ts 9 หลายเดือนก่อน

    Once you learn a thing or two about oops you know exactly what's going on. Thank you for the video

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

    Thank you John

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

    This is a very useful video.

  • @kilian9758
    @kilian9758 6 หลายเดือนก่อน

    Your tutorials are awesome! Though I wonder if this affects switch cases too. Can I always use switch cases or do I need to be cautious just like with the == operator?

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

    love your videos man !

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

    lmao, that head pop up at the beginning cracks me up!

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

    Small piece of feedback: title shoulda been ".equals() and == are not equal"
    Thanks for the great video!

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

    Good stuff brotherly.

  • @thegloriousgoldeneagle
    @thegloriousgoldeneagle 4 หลายเดือนก่อน

    I love your videos, thank you

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

    To the point explanation

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

    Superb sir❤

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

    Perfect concept

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

    Cristal clear!

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

    Hey pls make video on comparable comparator interface in java

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

    Excellent teacher

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

    Thank you john!!

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

    The underline is even if the primitive or non primitive or user defined type java will check for the memory location and not the values.. (if the values are same then uses same memory location).

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

    Best tuto ever

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

    Great lesson :)

  • @harshabhrito
    @harshabhrito 3 วันที่ผ่านมา

    Thank you sir.

  • @galirams9653
    @galirams9653 18 วันที่ผ่านมา

    John, please clarify this for me, in text, how would you declare and compare 2 string objects for equality?

  • @user-qw9gr4cb8z
    @user-qw9gr4cb8z ปีที่แล้ว

    You explained sth in 8minutes that my French prof couldn’t explain in 2 hours and made me hate Java for no reason . Thank you ❤

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

    Thank you

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

    ThankYou!!!

  • @AHMED-ry2gy
    @AHMED-ry2gy 2 ปีที่แล้ว

    dude, your videos are amazing

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

      I am going through you video and its very easy to understand . One more request can you please provide session for Stack vs heap memory.

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

    Can you do a video sometime on instanceof, thank you.

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

    Can you please make that video you promised on writing a good equals method?

  • @limonade-ru4vy
    @limonade-ru4vy 14 วันที่ผ่านมา

    You are a genius!!

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

    Really Really cool!

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

    Thank you so much

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

    Thanks. Useful, however you still did not cover how to compare 2 objects on the Dog example staring from 05:08

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

    The API contract also states that if you override equals() then you must override the hashcode(), it's an important detail!