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

  Рет қаралды 200,625

Coding with John

Coding with John

Күн бұрын

Пікірлер: 260
@rykageee
@rykageee 3 жыл бұрын
so far I've watched several videos with the same topic but this video only explained well. Thanks man!
@CodingWithJohn
@CodingWithJohn 3 жыл бұрын
Awesome! Very glad I was able to help!
@phillipmiller4642
@phillipmiller4642 7 ай бұрын
Agreed
@Dare24
@Dare24 2 жыл бұрын
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.❤
@magicalhats
@magicalhats 3 жыл бұрын
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.
@alexanderpanday
@alexanderpanday 8 ай бұрын
go away bootcamp people
@cjm101
@cjm101 2 жыл бұрын
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!
@aureliasam2092
@aureliasam2092 2 жыл бұрын
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.
@iruga7379
@iruga7379 2 жыл бұрын
OMFG please keep your content comming...im having a blast learning from you man. Im deeply grateful for all your lessons.
@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.
@streamity24
@streamity24 2 жыл бұрын
Really fascinated at how good you are able to explain. Thanks for the great video!
@theFUNkaarasChannel
@theFUNkaarasChannel 2 жыл бұрын
I just found your channel and the world just makes so much more sense now.
@Visionist
@Visionist 3 жыл бұрын
Simple and easy to understand. Thank you!
@brtkgromek
@brtkgromek 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! :)
@enigma6463
@enigma6463 3 жыл бұрын
😂😂
@terrypark3690
@terrypark3690 Жыл бұрын
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.
@AhmedMo0Ali
@AhmedMo0Ali 10 күн бұрын
what is iconic about Sir.John that he knows exactly how beginners feel or understand or even react with every single information he say Despite he is a high level engineer and sees every thing clear.
@olivierbegassat851
@olivierbegassat851 Жыл бұрын
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 🙂
@harlockgaming1476
@harlockgaming1476 Жыл бұрын
Love the Kramer picture in the back, my grandpa has one just like it! Thanks for the amazing videos!
@tonnytrumpet734
@tonnytrumpet734 7 ай бұрын
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.
@ovey2214
@ovey2214 3 жыл бұрын
That was incredibly well explained! Thanks a lot!
@manojpal4415
@manojpal4415 2 жыл бұрын
Had been scratching my head on a case similar to the example at last, luckily this video explained it. Huge thanks :)
@Fawstah
@Fawstah 2 жыл бұрын
This actually helped me understand why some of the code I was writing was initially breaking. Ty!
@cananozdemir8913
@cananozdemir8913 11 ай бұрын
I just bought his full Java course. Amazing explanation .
@BelayeAssefa1
@BelayeAssefa1 3 жыл бұрын
this channel always dropping gems. Respect.
@WildNature170
@WildNature170 2 жыл бұрын
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!!!!
@danieldanian8070
@danieldanian8070 2 жыл бұрын
This guy is the best as a learner and teacher guide
@micahrufsvold
@micahrufsvold 3 жыл бұрын
Small piece of feedback: title shoulda been ".equals() and == are not equal" Thanks for the great video!
@CodingWithJohn
@CodingWithJohn 3 жыл бұрын
.equals() != ==
@micahrufsvold
@micahrufsvold 3 жыл бұрын
@@CodingWithJohn even better!
@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!
@jesusromero71
@jesusromero71 2 жыл бұрын
tus videos tienen un gran valor, muchas gracias por compartir tu conocimiento
@LTZMSYAL
@LTZMSYAL 2 жыл бұрын
Thansk's John. Please don't stop your videos they are awesome
@DatCrossGuy
@DatCrossGuy 2 жыл бұрын
Thanks so much for the video. Genuinely looking forward to the "how to write a good equals method" vid!
@dhavewala
@dhavewala 3 жыл бұрын
John, this was an amazing tutorial! I had a query though; on the objects, do we override the equals() or is it inferred?
@wiktorstankiewicz3568
@wiktorstankiewicz3568 3 жыл бұрын
we override it
@fullfungo
@fullfungo 3 жыл бұрын
6:15
@michael_scarn_
@michael_scarn_ Жыл бұрын
Thanks John, your tutorials are very helpful. You are a great teacher, hats off!
@pawehericht2673
@pawehericht2673 7 ай бұрын
at 1:46 it is worth saying, that String one = "1"; String oneBis = "1"; when comparing one == oneBis will output true? what has changed and why String one = new String("1) gives us false when ==? The answer is: The String pool I believe
@ruzi173
@ruzi173 Жыл бұрын
This is just the best explanation..wow👏Thank you for all your videos🙏
@enfieldli9296
@enfieldli9296 2 жыл бұрын
Wow, noob here, didnt know those details till you explain it, massive thanks John!
@technicalboy1816
@technicalboy1816 3 жыл бұрын
I wish you were my lecturer at Uni. You have talent man!
@praveens9233
@praveens9233 Жыл бұрын
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
@ujjwals.dadwal8911
@ujjwals.dadwal8911 2 жыл бұрын
Thanks John, Mucha Gracias from Canada!
@amaralensheriff
@amaralensheriff Жыл бұрын
Thanks John, your tutorials are awesome.
@xrecovery9
@xrecovery9 23 күн бұрын
Thank you so much! You solved a bunch of hurdles I was facing while coding in Java. You earned a new Subscriber! By the way, what program are you using to code?
@cryptoInNutshellR
@cryptoInNutshellR Жыл бұрын
Thanks. Useful, however you still did not cover how to compare 2 objects on the Dog example staring from 05:08
@Eduardado
@Eduardado 2 жыл бұрын
Very clear. Awesome examples and also my eyes love the dark theme ^^
@akna1987
@akna1987 10 ай бұрын
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
@YusufDemir-gx7he
@YusufDemir-gx7he 2 жыл бұрын
It seems I've found my coding channel. Thanks for the video :)
@rahul64410
@rahul64410 3 жыл бұрын
Thanks for the video john seems like refreshing my basics
@shubhamkatwale6716
@shubhamkatwale6716 3 жыл бұрын
Very well explained Jonh, Thanks again ♥
@HR-pz7ts
@HR-pz7ts Жыл бұрын
Once you learn a thing or two about oops you know exactly what's going on. Thank you for the video
@9891254408
@9891254408 2 жыл бұрын
This is the best i have understoon so far...
@lamaspacos
@lamaspacos 10 ай бұрын
This channel is very very good.
@wayneinteressierts9973
@wayneinteressierts9973 Жыл бұрын
Great video as always. Thank you for your dedication!
@eshwarnag
@eshwarnag Жыл бұрын
the last part was really good!
@brunomartel4639
@brunomartel4639 Жыл бұрын
is it too bad if we declare Strings as literal all the time? like String string1= "hello" instead a declaring an object with it? I mean is there a reason to declare an object String?.
@robertod893
@robertod893 Жыл бұрын
Excellent video as always!
@scottcarter4526
@scottcarter4526 2 жыл бұрын
Might also be worth mentioning that you can use == with enum's as well.
@binilgeorge7358
@binilgeorge7358 3 жыл бұрын
But in your strings are immutable video, you said when initializing a string variable java points it to a pre existing string memory address. With that, here hello is already exist when you initialize the second string. Therefore both variable should point to same address, that is using == returns true. ? I am confused plz answer me.
@lumschente
@lumschente 3 жыл бұрын
the string itself is probably wrapped in a class and the class stores the reference to the string pool but the objects are initialized in different memory regions
@binilgeorge7358
@binilgeorge7358 3 жыл бұрын
@@lumschente Don't know if it is true, but that makes sense
@shravanbandari
@shravanbandari 2 жыл бұрын
I was thinking about the same, @john could you please clarify this question Here is the other video of your we were referring to 🙂 kzbin.info/www/bejne/eJucfquVgd1mp5Y
@konstantinzakharov5643
@konstantinzakharov5643 Жыл бұрын
I love this guy! I am hitting the Like button!
@nilou-bt
@nilou-bt 2 жыл бұрын
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 ❤
@علیحمیدی-س2ر
@علیحمیدی-س2ر Жыл бұрын
Thx for your clear presentation Sir
@colonelh.s.l.3834
@colonelh.s.l.3834 2 жыл бұрын
This is awesome! Can you do a video on priority queues and comparators, and how they come together?
@InfiniteWisdom1.0
@InfiniteWisdom1.0 Жыл бұрын
Thank you so much, your videos are pretty helpful 😊
@shama-_-
@shama-_- 2 жыл бұрын
thanks a lot you help me to understand the concepts
@bhagyakavijan9014
@bhagyakavijan9014 2 жыл бұрын
Thank you so much.. Your explanation is very clear...!!!
@simonjunior184
@simonjunior184 3 жыл бұрын
Amazing explanation. My Uni java lecturer even didn't taught us this important concept. Keep up the great job!
@laurentlefevre9233
@laurentlefevre9233 2 жыл бұрын
Nice job John !
@saranr4878
@saranr4878 2 жыл бұрын
Just the greatest explanation !
@Amy-zb4iq
@Amy-zb4iq 2 жыл бұрын
What’s the codes for .equals() in class Dog?
@iyhan1987
@iyhan1987 3 жыл бұрын
7:03 I guess almost everyone(who studies Java seriously) knows about the pool of strings cause it is a pretty common topic. I bet if you want really “to impress some nerds” you should show them some “pool of Integer” style tricks :)
@MasonJF
@MasonJF 2 жыл бұрын
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!".
@viv7531
@viv7531 3 жыл бұрын
Hello John, after You Ctrl + click on .equals (4:15 min) how did you go back? I mean how to hide all that info that appeared after Ctrl + clicking?
@matteoZattera
@matteoZattera 2 жыл бұрын
It just opens the file where .equals is defined, just close this file
@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).
@strigidae8939
@strigidae8939 3 жыл бұрын
Love your videos bro. Very helpful. Thanks a lot
@ayanokoji8456
@ayanokoji8456 2 жыл бұрын
Wow thanks man it is so well explain !
@GenjaOrigins
@GenjaOrigins 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
@galirams9653
@galirams9653 8 ай бұрын
John, please clarify this for me, in text, how would you declare and compare 2 string objects for equality?
@thalathotitharunprabhakar3390
@thalathotitharunprabhakar3390 3 жыл бұрын
Easy to understand. Thank you.
@bhukyasharath2015
@bhukyasharath2015 Жыл бұрын
Superb sir❤
@adamlasry5225
@adamlasry5225 2 жыл бұрын
Great lessons as usual. Thanks.
@LAZIO14
@LAZIO14 Жыл бұрын
Thanks! Your videos are great!
@danielcommins1285
@danielcommins1285 3 жыл бұрын
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!
@alyankhan806
@alyankhan806 2 жыл бұрын
The API contract also states that if you override equals() then you must override the hashcode(), it's an important detail!
@Sui-Zan
@Sui-Zan 3 жыл бұрын
Orange is the new black, John. You look great! Thank you very much for the videos. You make java seem so simple to me.
@altamashsabri8142
@altamashsabri8142 2 жыл бұрын
Amazing explanation, thanks alot
@Coccoutube
@Coccoutube 2 жыл бұрын
Thanks John!
@GaryChike
@GaryChike 3 жыл бұрын
This is a gotcha for those coming from C#. Great explanation John!
@surkesden
@surkesden 3 жыл бұрын
Good explanation! What about enum comparation? What should I use?
@iamnotfamous6591
@iamnotfamous6591 9 ай бұрын
but in one video you said that java make different variables but when we store same values to it java make them point to the same locations where the value is stored!!! why??
@cestmoi5248
@cestmoi5248 2 жыл бұрын
wow, very well explained. Thank you
@Zalaniar
@Zalaniar 2 жыл бұрын
I was gonna say something about the weird use of a string constructor at the beginning, but it's a good thing I decided to wait, lol. IIRC, the javadoc even yells at people about wanting to use == for strings which I find hilarious.
@AHMED-ry2gy
@AHMED-ry2gy 3 жыл бұрын
dude, your videos are amazing
@pankajthorat4606
@pankajthorat4606 3 жыл бұрын
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.
@Programming-for-all-u2l
@Programming-for-all-u2l 2 жыл бұрын
Excellent teacher
@dylangovender
@dylangovender 2 жыл бұрын
Amazing tutorial!
@InfoBuzz1130
@InfoBuzz1130 2 жыл бұрын
Hey pls make video on comparable comparator interface in java
@DanielOliveira-ru7mt
@DanielOliveira-ru7mt 2 жыл бұрын
Thanks Johnny Sins
@lyrixvibz
@lyrixvibz 7 ай бұрын
Please be polite with your words👍
@1blkvinci
@1blkvinci 6 ай бұрын
@@lyrixvibzhe said thank you
@lyrixvibz
@lyrixvibz 6 ай бұрын
@@1blkvincido you know Johnny sins?💀
@SifatUllah-12
@SifatUllah-12 5 ай бұрын
​@@1blkvinciThat's not the right way to say thank you.
@HIMANSHURAGHAV-km8rr
@HIMANSHURAGHAV-km8rr 5 ай бұрын
Thanks john 😄
@amruthashekar3544
@amruthashekar3544 6 ай бұрын
Hello John, please answer why i am getting false in first case? String str1 = new String("hello"); String str2 = new String("hello"); System.out.println(str1.equals(str2)); and String str = new String("java"); String rev = new String("avaj"); System.out.println(str.equals(rev)); how string comparision is done, is it character by character?
@SupunWithana-t8x
@SupunWithana-t8x 5 ай бұрын
I think better you recheck 1st case, it has to be true
@aymengouja3895
@aymengouja3895 2 жыл бұрын
thanks a lot !!! awesome explanation
@potatofypotatofy7772
@potatofypotatofy7772 2 жыл бұрын
Thank you John
@stacywen7908
@stacywen7908 2 жыл бұрын
thank you so much! very helpful!
@hba6018
@hba6018 3 жыл бұрын
String Pool, the place where are inline strings are saved, that's why you use new String("hello")
@JPS13Laptop
@JPS13Laptop 3 жыл бұрын
As a python programmer, I definitely see myself getting confused if I were to ever get into Java. Thanks for the explanation :)
@tazogochitashvili6514
@tazogochitashvili6514 3 жыл бұрын
You shouldn't look too deep into the difference between "is" and "=" in python then lol
@JPS13Laptop
@JPS13Laptop 3 жыл бұрын
@@tazogochitashvili6514 I actually do realise the difference between the two. But I don't use 'is' in my own code tbh. Also it annoys me that Java uses == for object comparison whereas Python uses it for value comparison.
@palmolive4541
@palmolive4541 3 жыл бұрын
@@JPS13Laptop Java doesn’t use == for object comparison, that was the whole point of this video
@JPS13Laptop
@JPS13Laptop 3 жыл бұрын
@@palmolive4541 It appears that I still don't fully grasp what an object is. Also it seems that `is` in Python is what `==` does in Java, which is still annoying tbh.
@tazogochitashvili6514
@tazogochitashvili6514 3 жыл бұрын
@@JPS13Laptop that means that you don't understand either "is" in python or "==" in Java
@lararifai7074
@lararifai7074 3 жыл бұрын
Very interesting ,thank you .
@mdemranalamin166
@mdemranalamin166 2 жыл бұрын
thank you, sir. !! great explanation.
Array vs. ArrayList in Java Tutorial - What's The Difference?
17:36
Coding with John
Рет қаралды 577 М.
Java Strings are Immutable - Here's What That Actually Means
7:06
Coding with John
Рет қаралды 628 М.
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
Java's Creators Rejected Multiple Inheritance - Here's Why
13:14
Coding with John
Рет қаралды 71 М.
Lambda Expressions in Java - Full Simple Tutorial
13:05
Coding with John
Рет қаралды 794 М.
#95 Comparator vs Comparable in Java
15:43
Telusko
Рет қаралды 226 М.
Checked vs. Unchecked Exceptions in Java Tutorial - What's The Difference?
10:14
#58 Object Class equals toString hashcode in Java
12:00
Telusko
Рет қаралды 140 М.
Java Unit Testing with JUnit - Tutorial - How to Create And Use Unit Tests
21:35
Vectors in Java: The 1 Situation You Might Want To Use Them
16:13
Coding with John
Рет қаралды 88 М.
Generics In Java - Full Simple Tutorial
17:34
Coding with John
Рет қаралды 1,1 МЛН