Java interview question on hashcode() and equals() || Java collection interview questions on HASHMAP

  Рет қаралды 344,083

Selenium Express

Selenium Express

Күн бұрын

This tutorial covers a very popular java interview question on hashcode and equals method in java.By asking this question interviewer checks
your understanding of java collections and wrapper class together.
So this tutorial covers few questions like :
1) how to stop duplicate entry to a hashmap with respect to a customized class
2) How the duplicate entry is getting rejected in a map with respect to a wrapper class.
3) Comparison between a customized class and a wrapper class map size.
So as we know the two most important java object class methods are hashcode and equals and they have a various impact when it comes to java collection.
Soon I am going to release another tutorial on java hashcode and equals method, where we are going to learn everything from scratch.To get a notification for that tutorial please subscribe to my channel by clicking the below link.
/ @seleniumexpress
Stay tuned and like my Facebook page for more.
/ seleniumexpress
Music :
-----------
credits : -
1)
Adventures by A Himitsu / a-himitsu
Creative Commons - Attribution 3.0 Unported- CC BY 3.0
creativecommons.org/licenses/b...
Music released by Argofox • A Himitsu - Adventures...
Music provided by Audio Library • Adventures - A Himitsu...
2)
NCM Epic Music Ender Guney
/ ncmepicmusic
-----
intro template :
wkzfaq.info

Пікірлер: 169
@SeleniumExpress
@SeleniumExpress 5 жыл бұрын
For step by step explanation on hashcode and equals() in Java, please check out my new playlist by clicking the link below kzfaq.info/sun/PL3NrzZBjk6m95SR6WzhnOGGCjXZpCoO-k
@ChongSLee
@ChongSLee 5 жыл бұрын
i get invalid parameters... is this right url? thanks.
@vimalsubha
@vimalsubha 6 жыл бұрын
I like the way you started the problem and slowly decoding...
@khagendrakumar8025
@khagendrakumar8025 6 жыл бұрын
i saw lots of video but still there is confusion in my mind ,,,after seeing this video i understand 100% of this fundamental,thank u sooooo much,keep going we will support you.
@diavijay08khush94
@diavijay08khush94 4 жыл бұрын
I have become fan of you.... thanks for the informative vedio....and for the people it's not the fake accent ... it's his confidence that he gained due to knowledge....so please don't discourage any knowledgeable person like this...
@madhavanananthan7077
@madhavanananthan7077 2 жыл бұрын
Master level explanation, really hats off Actually I watched several videos to understand this concept. But this one is 🔥 simply
@manojdehran4698
@manojdehran4698 6 жыл бұрын
You are a real coder, otherwise most of the people talks about theory. Keep up the good work !!
@coolfreaks68
@coolfreaks68 5 жыл бұрын
You are what ?
@sanketh768
@sanketh768 2 жыл бұрын
this helped me out with my issue today, thank you ver much
@niteshpandey8207
@niteshpandey8207 Жыл бұрын
That's Amazing I'am not aware about Wrapper class that it having equal and hashcode.
@techsteering
@techsteering 5 жыл бұрын
Excellent. Thanks for sharing your knowledge.
@mayerbeats6754
@mayerbeats6754 6 жыл бұрын
Спасибо! Thank you from Russia!
@SeleniumExpress
@SeleniumExpress 6 жыл бұрын
You are welcome !!
@tejusree2072
@tejusree2072 6 жыл бұрын
Thank u sir for the great tutorial.This is fundamental and root to start.This is what we missed till now in other tutorials.very unique explanation.Thank u ..big fan :)
@SeleniumExpress
@SeleniumExpress 6 жыл бұрын
Thanks, Teju..
@sangeethchitravel3092
@sangeethchitravel3092 4 жыл бұрын
Good explanation. Addition to that I wanna add one more point, if u add your custom object as key of map then it should be immutable. So u have to make your employee object as immutable object as string class.
@aakashdetwal9950
@aakashdetwal9950 2 жыл бұрын
Your way of explain is understandable it is helpful
@swapnilshinde8110
@swapnilshinde8110 3 жыл бұрын
it,s Really Helpful me this video..........Thanks a lot Sir.
@helishah9065
@helishah9065 5 жыл бұрын
Amazing explanation! Thanks a lot :)
@sreenivasl5383
@sreenivasl5383 Жыл бұрын
Explained very nicely.. The way of started, the way of required info from api document, different type objects.. 👏
@muralimohan7097
@muralimohan7097 3 жыл бұрын
The way you are explaining the concept with example is awesome and it clear to understand
@krishnasingh9111
@krishnasingh9111 5 жыл бұрын
Very help full for beginners thank you :)
@erictang4447
@erictang4447 4 жыл бұрын
Thank you for explanation. The visual animation is very helpful.
@salenaluu8477
@salenaluu8477 3 жыл бұрын
Thank you so much
@ponsivakumarmanoharan4994
@ponsivakumarmanoharan4994 3 жыл бұрын
Good one
@sulavagarwal3561
@sulavagarwal3561 6 жыл бұрын
u got great explanation skills
@hetalrachh5665
@hetalrachh5665 3 жыл бұрын
Amazing and very simple explanation, Thanks !!
@amitaswar7010
@amitaswar7010 5 жыл бұрын
I like the ending music so much and video too thank you bhai
@AllinOne-et2on
@AllinOne-et2on 2 жыл бұрын
I am watching on Sep 2021. Great job bro. ❤️❤️
@shanthinis5667
@shanthinis5667 Жыл бұрын
Very nice explanation.... Awesome 👍
@somethingforyou891
@somethingforyou891 5 жыл бұрын
Superb explanantion. Thank you
@letusmeet5427
@letusmeet5427 3 жыл бұрын
so super explanation , really it's wonderful explanation. You borned for us only. so so sooooo nice of you.. Thank you soooooo much.
@lux27.42
@lux27.42 4 жыл бұрын
this video easy to understand :) thankyou so much.
@nareshch6454
@nareshch6454 2 жыл бұрын
Wonderful explaination brother
@kanagarathinamannamalai8020
@kanagarathinamannamalai8020 5 жыл бұрын
Nice Explanation bro.Thanks👍..
@1976balakrishna
@1976balakrishna 2 жыл бұрын
nice one
@lordgreat6051
@lordgreat6051 2 жыл бұрын
Because map uses hash to target keys! brilliant example thanks
@prashantthite9061
@prashantthite9061 2 жыл бұрын
Perfect explanation that I want. Now I am clear with my doubts in hastable. Thanks and please create more video on programming.
@danceayush8128
@danceayush8128 2 жыл бұрын
Now I actually got the point.. Thanks brother 👍
@premkirankatinedi4479
@premkirankatinedi4479 5 жыл бұрын
Wow...this is to the point. Thanks a lot
@harshav3902
@harshav3902 4 жыл бұрын
Thanks for the explanation dude. It helped.
@OrdinaryTalesofSamriddhi
@OrdinaryTalesofSamriddhi 3 жыл бұрын
You describe everything in such an organized and nice manner. No one can compete you. From covering the most trivial detail to covering the complex thing of every concept is what makes you unique. Keep up the good work. Looking forward to many more informative videos from you.
@premkirankatinedi4479
@premkirankatinedi4479 5 жыл бұрын
Simply Awesome!!
@felixkimutai8478
@felixkimutai8478 5 жыл бұрын
Great! Thank you.
@subhashininallapati2080
@subhashininallapati2080 3 жыл бұрын
Excellent teaching. May I know where I can find all your Java interview QA videos, Selenium interview QA , Java tutorial and Selenium tutorial at one place? Could you please share. I am learning a lot from your videos.
@oussamabr5851
@oussamabr5851 4 жыл бұрын
Excellent explanation! Thanks.
@pratikalhat9484
@pratikalhat9484 2 жыл бұрын
very nicely explained
@tasteanotherbite1265
@tasteanotherbite1265 Жыл бұрын
Amazing explanation 👌
@srikanth29
@srikanth29 6 жыл бұрын
Thank u very much. Very helpful and clear
@SeleniumExpress
@SeleniumExpress 6 жыл бұрын
Thanks, Sri Kanth.
@trendingtechnologiesit924
@trendingtechnologiesit924 6 жыл бұрын
Simply awesome
@ElCanalDelPadrino
@ElCanalDelPadrino 2 жыл бұрын
Excellent explanation!!
@PoonamSharma-gy3ky
@PoonamSharma-gy3ky 2 жыл бұрын
Really very helpful content with proper explaination
@mbrajucse
@mbrajucse 3 жыл бұрын
Super bro. Nice explaination.👍
@ajaysuresh3781
@ajaysuresh3781 2 жыл бұрын
Very nice clear explanation Sir. Thank you 👍
@saiadaikappan
@saiadaikappan 3 жыл бұрын
Very clear explanation, thank you !!! your voice makes the explanation more interesting.
@arindamroy7671
@arindamroy7671 3 жыл бұрын
Not really !
@harit9380
@harit9380 4 жыл бұрын
Great Video!! Understood clearly!
@deepikajagadees7996
@deepikajagadees7996 2 жыл бұрын
Thank you a lot for the great explanation
@tw5529
@tw5529 3 жыл бұрын
Great Explanation👌 Thanks a Lot :-) . BTW, which software are you using for making this video?? It looks so attractive 😊
@kumarvijayag
@kumarvijayag 2 жыл бұрын
best example, basic point explained, but still should have talked more about equals and hashcode methods
@sauravsrivastava9019
@sauravsrivastava9019 2 жыл бұрын
Good explanation
@prabudhabansode6953
@prabudhabansode6953 2 жыл бұрын
Nicely explained. Thank you!
@deepar781
@deepar781 5 жыл бұрын
Its good. Keep Posting bro
@mohanas6697
@mohanas6697 6 жыл бұрын
Hi, if possible, please explain why we need to override hashcode() if we are overriding equals()...By the way, your accent doesn't matter only subject matters...Keep it going :-) you are doing a great job...
@vishalgaikwad873
@vishalgaikwad873 6 жыл бұрын
Bcz of contract between .equals()/ hashCode() method. ->Two equivalent object should be placed in same bucket and There HASHCODE must be same. s1.equals(s2); && s1.hashCode()==s2.hashCode();
@coolfreaks68
@coolfreaks68 5 жыл бұрын
I shall add in a few more points after what Gaikwad said . • Let's consider we have a HashSet which already has 100 elements preloaded in it. • Let's say, we want to add a new element, ie. the 101th element to the set. • The HashSet is designed to keep unique elements only. So when the 101th element is introduced, the add() logic will compare the 101th element, with each of the previously stored 100 elements. Right ? This is where hashcode() comes to rescue. If a proper hashcode() logic has been implemented, then the addition of new elements to the HashSet, will require much fewer equality comparisons. • For example without hashcode() the add() method has to do 100 equality checks. But with a good hascode() logic, the add() operation may not require more that 20 checks.
@srinathravichandran8796
@srinathravichandran8796 5 жыл бұрын
@@coolfreaks68 Hi subhadeep..I can get ur point that with a good hashcode logic, we can avoid more comparisons.could you pls explain how it minimizes the comparison?
@coolfreaks68
@coolfreaks68 5 жыл бұрын
@@srinathravichandran8796 - Obviously because each Hash bucket usually has fewer elements than its parent Hash Set. Only a very bad hascode() logic can push all the elements of HashSet into just one Hash bucket - giving no performance improvement. A good hashcode() logic on the other hand, distributes the elements among multiple buckets, with each bucket having very less number of elements and with all the buckets having almost equal number of elements. Eg : if you have , lets say a 100 element in hash set. A bad hashcode() logic will push all 100 elements into 1 bucket , leaving other buckets empty ! A good hashcode() logic will push 10 elements to each of the 10 buckets. So whenver you are searching , first you find out the bucket number, then you do a binary search inside that specific bucket. So there is performance improvement.
@sergioantoniomartinez9227
@sergioantoniomartinez9227 4 жыл бұрын
@@coolfreaks68 that's a clever way of handling buckets, thank you
@RiyazParasara
@RiyazParasara 5 жыл бұрын
Great thanks.
@abhinavghosh725
@abhinavghosh725 4 жыл бұрын
finally someone clearly explained it!
@saranyan3910
@saranyan3910 2 жыл бұрын
Wow! Awesome explanation 🙏
@rameshbabu5754
@rameshbabu5754 4 жыл бұрын
Below my all question are more help full in interview point of view. So, Could you please explain below all videos to me
@sonyguptayourdearestsony
@sonyguptayourdearestsony 5 жыл бұрын
nice good explanation
@trendytopics-
@trendytopics- 2 жыл бұрын
THANK YOU SO MUCH!
@macherladevasundaram4928
@macherladevasundaram4928 3 жыл бұрын
Very good explanation bro.. Thank you..
@priyankaraut9289
@priyankaraut9289 4 жыл бұрын
Gud information keep going
@peedrap987654321
@peedrap987654321 6 жыл бұрын
Excellent
@srilakshmi5922
@srilakshmi5922 4 жыл бұрын
simply awesome
@vishnupriya80
@vishnupriya80 4 жыл бұрын
hi your videos were really helpful. do you have any videos related to regular expressions?
@kingajable
@kingajable 3 жыл бұрын
you doing great job buddy keep it up
@ARI-em6me
@ARI-em6me 5 жыл бұрын
Very very clear explanation. Plse upload how to upload webproject deployed server
@DavidCervantesmrclutch
@DavidCervantesmrclutch 3 жыл бұрын
Nice video Bro
@alittlecoding
@alittlecoding 4 жыл бұрын
Good job. thanks
@atiqulny
@atiqulny 4 жыл бұрын
You are a genius
@rameshbabu5754
@rameshbabu5754 4 жыл бұрын
Could you please explain the oops (Abstraction, Inheritance, Encapsulation, Polymorphism ) concepts in java with theory and real examples
@shalabhdixit
@shalabhdixit 5 жыл бұрын
No where the difference between hashCode and equals is explained. Also please explain why we need to generate the hashcode and equals method and how did it make the values change from 2 to 1
@SeleniumExpress
@SeleniumExpress 5 жыл бұрын
Hi Shalabh, This is a video from my interview questions and answers series. So I haven't covered the concept in this video rather this is just an interview question that I am trying to explain. I will be posting a complete video on this concept in the coming week.
@shalabhdixit
@shalabhdixit 5 жыл бұрын
@@SeleniumExpress ok. Thank you!
@merajulhaque9107
@merajulhaque9107 4 жыл бұрын
@@SeleniumExpress Can you please share the link for the complete concept video.
@dsgtechinfo5639
@dsgtechinfo5639 3 жыл бұрын
Thanks a lot friend
@sandeepsandy-zm5ve
@sandeepsandy-zm5ve 6 жыл бұрын
nice explntn..
@himachaliravi
@himachaliravi 6 жыл бұрын
Good example
@rameshbabu5754
@rameshbabu5754 4 жыл бұрын
Could you please explain the Internal mechanism of HashSet in java with theory and real time examples
@chloeren9175
@chloeren9175 Жыл бұрын
Thank you so much for your great explanations! so all i need to do is to go to Id=>source=>generate hashcode( )and equal(),so i cn get the map.size(1),right?
@shubhamraj5184
@shubhamraj5184 3 жыл бұрын
Wow thanks 💓
@ShubhamGupta-fm7lv
@ShubhamGupta-fm7lv 5 жыл бұрын
I don't know why I didn't see this video earlier. Got this in an interview and I wasn't able to answer.
@JaspreetSingh-ln1yc
@JaspreetSingh-ln1yc 3 жыл бұрын
same bro,same!!
@krishnasuripaka2480
@krishnasuripaka2480 4 жыл бұрын
Super Brother...
@subramanianchenniappan4059
@subramanianchenniappan4059 4 жыл бұрын
Thanks a lot
@AtulMishra-rs5os
@AtulMishra-rs5os 5 жыл бұрын
Explanation was helpful but a bit confusing during few moments. Two advice for you if you accept it.... First: Try to speak in Indian accent of English so it won't fake. Second: Reduce the redundancy of some words you speak very frequently i.e. 'Over here'. You don't complete your most of the sentences without prefixing or suffixing 'Over here' ;). Please don't take it personal and also remember "Your critics are your biggest followers".
@rajeshchouhan458
@rajeshchouhan458 5 жыл бұрын
Agreed men
@SudhanshuSrivastavaIndia
@SudhanshuSrivastavaIndia 5 жыл бұрын
I have same opinion. Sometimes it made me feel annoying. Fantastic tutorial but need to improve the above mentioned points.
@august24outing5
@august24outing5 4 жыл бұрын
Agree, that's the worst part of it...be natural...
@aishwaryarokade1150
@aishwaryarokade1150 5 жыл бұрын
Thank you
@shubhashree3853
@shubhashree3853 6 жыл бұрын
Can we avoid duplicate object reference by implementing hascode() n equal () methods?
@digvijaynegi6917
@digvijaynegi6917 5 жыл бұрын
Thanks
@damodaranm3044
@damodaranm3044 4 жыл бұрын
Wow r Ally good .and why don't you make videos in following concept cuz there is no good videos in KZfaq threads collection jsf spring
@bakhromachilov8456
@bakhromachilov8456 4 жыл бұрын
Perfect
@gauravsharma875
@gauravsharma875 3 жыл бұрын
How come emp1 and emp2 having the same hashcode? Can someone please help
@commonman8540
@commonman8540 Жыл бұрын
HI Avinash, When we use jpa repository.saveOrUpdate(product);, my product object has 1 lak records, will it accept? Is there any limitation ?
@rameshgollapudi588
@rameshgollapudi588 6 жыл бұрын
Very nice
@SeleniumExpress
@SeleniumExpress 6 жыл бұрын
Thanks, Ramesh
@kssinfonet2394
@kssinfonet2394 2 жыл бұрын
Dear Abhilash sir i have one que. which empoyee object will hashmap put 1st ya 2nd after using hashmap and equal method😊
@aayush-zw1mx
@aayush-zw1mx 3 жыл бұрын
But Sir the two employees object hold different memory addresses and in a map we cannot have same keys and in this case the keys emp1 and emp2 are already different only the value they contain are same .So how are the entry set duplicates.Can you pls explain
@priyankaraut9289
@priyankaraut9289 4 жыл бұрын
Do videos on java framework
@rthiaga
@rthiaga 5 жыл бұрын
In the hashCode method why 31 is multiplied by 1 and id. We can directly return the id right?
@raghavanaliassaravananm1546
@raghavanaliassaravananm1546 5 жыл бұрын
No. That is really required for Hashing, which recommends the key value (here 'id') to be multiplied by a prime number. For all sake of randomness. Most people take 31 as a good prime number to have a better sampling.
@JaishriVemuganti
@JaishriVemuganti Жыл бұрын
I put the code as you shown in my side and in both cases ham getting size =2
DEFINITELY NOT HAPPENING ON MY WATCH! 😒
00:12
Laro Benz
Рет қаралды 46 МЛН
Мы никогда не были так напуганы!
00:15
Аришнев
Рет қаралды 6 МЛН
Survival skills: A great idea with duct tape #survival #lifehacks #camping
00:27
Khó thế mà cũng làm được || How did the police do that? #shorts
01:00
Garbage collection in Java, with Animation and discussion of G1 GC
44:20
Ranjith ramachandran
Рет қаралды 484 М.
Optionals In Java - Simple Tutorial
15:53
Coding with John
Рет қаралды 201 М.
02. Equals and HashCode Contract & Different Variations
11:19
WebEncyclop Tutorials
Рет қаралды 52 М.
Set and HashSet in Java - Full Tutorial
20:43
Coding with John
Рет қаралды 202 М.
DEFINITELY NOT HAPPENING ON MY WATCH! 😒
00:12
Laro Benz
Рет қаралды 46 МЛН