.equals() vs. == in Java - The Real Difference
HTML-код
- Опубликовано: 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 Наука
so far I've watched several videos with the same topic but this video only explained well. Thanks man!
Awesome! Very glad I was able to help!
Agreed
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.❤
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!
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.
Really fascinated at how good you are able to explain. Thanks for the great video!
Simple and easy to understand. Thank you!
OMFG please keep your content comming...im having a blast learning from you man. Im deeply grateful for all your lessons.
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 🙂
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.
go away bootcamp people
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.
That was incredibly well explained! Thanks a lot!
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.
Had been scratching my head on a case similar to the example at last, luckily this video explained it. Huge thanks :)
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!!!!
I just found your channel and the world just makes so much more sense now.
tus videos tienen un gran valor, muchas gracias por compartir tu conocimiento
Thanks John, your tutorials are very helpful. You are a great teacher, hats off!
This actually helped me understand why some of the code I was writing was initially breaking. Ty!
this channel always dropping gems. Respect.
Very well explained Jonh, Thanks again ♥
Great video as always. Thank you for your dedication!
This is awesome! Can you do a video on priority queues and comparators, and how they come together?
Thanks for the video john seems like refreshing my basics
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
Thanks so much for the video. Genuinely looking forward to the "how to write a good equals method" vid!
John, this was an amazing tutorial!
I had a query though; on the objects, do we override the equals() or is it inferred?
we override it
6:15
Love your videos bro. Very helpful. Thanks a lot
Love the Kramer picture in the back, my grandpa has one just like it! Thanks for the amazing videos!
I just bought his full Java course. Amazing explanation .
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
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!
Very clear. Awesome examples and also my eyes love the dark theme ^^
Sir I have been watching your videos for around 30 hours last 3 days, thank you so much this is great content I am starting to actually understand Java and see how things from different videos relate to each other, sometimes I can guess what you are going into with your train of thoughts, very well put together videos.
Thanks John, your tutorials are awesome.
Easy to understand. Thank you.
Great lessons as usual. Thanks.
This is just the best explanation..wow👏Thank you for all your videos🙏
I wish you were my lecturer at Uni. You have talent man!
Thansk's John. Please don't stop your videos they are awesome
Thanks John, Mucha Gracias from Canada!
thanks a lot you help me to understand the concepts
Might also be worth mentioning that you can use == with enum's as well.
Thank you so much, your videos are pretty helpful 😊
Thx for your clear presentation Sir
Good explanation! What about enum comparation? What should I use?
wow, very well explained. Thank you
Thank you so much.. Your explanation is very clear...!!!
Very interesting ,thank you .
the last part was really good!
Wow, noob here, didnt know those details till you explain it, massive thanks John!
thank you, sir. !! great explanation.
This guy is the best as a learner and teacher guide
Excellent video as always!
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!
Small piece of feedback: title shoulda been ".equals() and == are not equal"
Thanks for the great video!
.equals() != ==
@@CodingWithJohn even better!
It seems I've found my coding channel. Thanks for the video :)
Nice job John !
Wow thanks man it is so well explain !
Amazing explanation, thanks alot
Thanks! Your videos are great!
thanks a lot !!! awesome explanation
thank you so much! very helpful!
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! :)
😂😂
love your videos man !
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?
Amazing tutorial!
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
This is a very useful video.
This is the best i have understoon so far...
Just the greatest explanation !
Great lesson :)
This channel is very very good.
Thanks John!
I love this guy! I am hitting the Like button!
Once you learn a thing or two about oops you know exactly what's going on. Thank you for the video
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).
Thank you john!!
Can you please make that video you promised on writing a good equals method?
Thank you John
Good stuff brotherly.
The API contract also states that if you override equals() then you must override the hashcode(), it's an important detail!
Superb sir❤
Can you do a video sometime on instanceof, thank you.
Excellent teacher
Perfect concept
dude, your videos are amazing
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.
String Pool, the place where are inline strings are saved, that's why you use new String("hello")
nice one John :)
John, please clarify this for me, in text, how would you declare and compare 2 string objects for equality?
Hey pls make video on comparable comparator interface in java
Thank you so much
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 ❤
See this is interesting, because I thought with Javas memory management scheme that it uses and forces strings to be immutable would reference the same object in memory, even though the variables are two seperate ones.
Eg. I was under the impression that
String string1 = "James";
String string2 = "James";
these would both point to the same object in memory because these are the same value, which you would think would cause the == operator to go "Oh hey, this is true!".
Cristal clear!
I love your videos, thank you
To the point explanation
lmao, that head pop up at the beginning cracks me up!
Really Really cool!
Thank you sir.
Thanks. Useful, however you still did not cover how to compare 2 objects on the Dog example staring from 05:08