JAVA Collection Interview QNA - How Hashmap works internally? | hashcode() , equals() & THE Contract

  Рет қаралды 12,508

Selenium Express

Selenium Express

Күн бұрын

Few of the popular JAVA Collection Interview questions comes from the Hash based collections. The HashSet, Hashmap and the method like hashcode() , equals() & THE Contract between the hashcode() and equals() are the most popular one.
In this video, we are going to discuss regarding the above questions and we will add another important JAVA Collection Interview QNA to our “ java interview questions and answers “ playlist.
We will start this session with some hashset related questions and the internal working of hashset, and these questions has a direct relation with the topic that we will be covering in this session below.
TIMESTAMP
-----
00:00:00 - Introduction - JAVA Collection Interview QNA
00:02:46 - Hashset In Java - Odd behaviour
00:14:47 - Java equals() - Deep Dive
00:31:11 - Java hashcode() - Deep Dive
00:56:27 - How Hashmap works internally?
01:16:59 - Hashmap internals - Debugging
01:39:50 - hashcode() , equals() & THE Contract
01:46:40 - Integer Caching - Integer as a Hashmap key
01:48:46 - Scenario 1 - No hashcode() and equals() overridden
02:02:49 - Scenario 2 - Override hashcode() but not equals()
02:11:19 - Scenario 3 - Override equals() but not hashcode()
When we use custom objects as a Hashmap key, we should consider overriding hashcode() and equals() methods.
Incase the hashcode() and the equals() are not overridden, the object class hashcode and equals participate during the object insertion and,
causes in duplicate insertions to the map.
The hashcode() methods determines the hash of an object which later used for index calculation.
The Index is a smaller number which is considered as the bucket number where an Hashmap
Entry will go.
As the index is calculated from a hashcode it is very important that, the index should be same for duplicate objects. By doing so we can send all duplicate objects into a single bucket resulting the equals checks to trigger. The equals method decides whether the objects are equals and stop duplicate entries to be inserted to the map. So we should override the equals method If the component is getting used as a key inside a Hashmap.
We should give implementation to equals method in such a way that it can determine the object equality (may be based on the object reference / content).
We should follow the below two golden rules while we are writing our custom equals and hashcode methods
1. Two equal object should have the same hashcode.
2. If the hashcode of the two objects are same, that don’t define the object equality.
Let’s go ahead and have a deep dive into hashcode , equals , hashset, hashmap, and the internal working of hashset and hashmap.
Hope this video will help for your java interview preparation.
#HashmapInternal #Hashmap #JavaCollectionFramework #Java
For More free/paid courses visit
www.seleniumexpress.com
LINKS AND FREE LEARNING RESOURCES
========
Watch my new mock interview series for java developers
• Java interview questio...
Watch Spring boot Hot topics
• @Reposicotry Vs @Servi...
Java Interview / Question and Answer series
• Java collections inter...
Explain spring Bean Lifecycle
• REAL-TIME: Spring Bean...
spring core
• Spring framework tutor...
spring mvc
• Spring MVC course intr...
spring mvc intermediate
• [INTERMEDIATE] Spring ...
Spring JDBC
• Spring JDBC Course Pre...
spring live project
• #1 Build and Deploy A ...
SPRING SECURITY COURSE[NEW]
• Spring Security Course...
For more courses visit
www.seleniumexpress.com
Any time you are getting stuck with issues, Feel free to ask for support.
You can send mail to seleniumexpress@gmail.com
you can ping me on my Facebook page
/ seleniumexpress
Make sure to join my private Facebook page (Ask me here)
“SeleniumExpress - Support"
/ 187000222361579
you can ask for support in my website forum
www.seleniumexpress.com
Subscribe to my youtube channel
/ @seleniumexpress
Follow me on Insta
/ selenium_express

Пікірлер: 32
@chintu4609
@chintu4609 Жыл бұрын
Video was long but much better than watching a bollywood movie....learned alot from scratch. Thank you so much sir but i wanted to say that you are a very underrated teacher.
@arjunvetal2274
@arjunvetal2274 Жыл бұрын
from scratch thats the uniqueness of ur channel ....love this channel
@fatmao99
@fatmao99 11 ай бұрын
the explanation is very understandable and clear. I wish we have a chance to learn Threads related questions' answers from you
@ManishYadav-jx5mb
@ManishYadav-jx5mb 4 ай бұрын
At 27:9 m, Integer i1=100 and Integer i2=100 both i1 and i2 refer to the same object in the caches pool for Integer wrapper class so if you use == keyword that time it returns true.
@ashokmergaveni9414
@ashokmergaveni9414 2 ай бұрын
yes, it's applicable to -127 to 127
@nguyenquan4836
@nguyenquan4836 Жыл бұрын
I already like deep dive videos from you ❤
@knizam4552
@knizam4552 Жыл бұрын
Superbb Explanation... Got a clear picture... Keep doing more like this... Will helpful alot
@ankurpachegaokar9234
@ankurpachegaokar9234 9 ай бұрын
-128 to 127 is the default size. But javadoc also says that the size of the Integer cache may be controlled by the -XX:AutoBoxCacheMax= option
@chukwukaegbujio1450
@chukwukaegbujio1450 8 ай бұрын
Great content! Good learning resources for all levels of developers
@MHK958
@MHK958 Жыл бұрын
I like you are adding chapters time slot wise thanks
@nitinchoudhary9015
@nitinchoudhary9015 Жыл бұрын
I am a lucky person I got this channel for spring
@aayush5474
@aayush5474 Жыл бұрын
Can you please make video on spring cloud
@thiestmayank
@thiestmayank Жыл бұрын
Yes, please make deep dive videos on spring Cloud @Abhilash
@ahmed-777
@ahmed-777 Жыл бұрын
Very helpful. Thank you
@tzhynt
@tzhynt 6 ай бұрын
Thanks so much for your great lesson
@ADNANKhan-gy7ln
@ADNANKhan-gy7ln 3 ай бұрын
Congratulations sir for 100k
@berkanyildiz5343
@berkanyildiz5343 8 ай бұрын
Great!
@srigakolapuatchuthasai5929
@srigakolapuatchuthasai5929 Жыл бұрын
Thanks abhi❤
@santhoshchandran6952
@santhoshchandran6952 Жыл бұрын
Thank you abhi
@suseesenthil417
@suseesenthil417 8 ай бұрын
Please please post more Java interview questions and deep dive
@teklehaimanotatikilt1435
@teklehaimanotatikilt1435 Жыл бұрын
hi abilsh the way you teach its brilliant but i have some questions how to know how many dispatcher servlet is enough for the application and also how to create multiple dispatcher servlet in spring boot and how to install spring boot app in company server can you please make videos and let me know thanks.
@adelhatary7473
@adelhatary7473 Жыл бұрын
Hello I really appreciate your work but you still go from course to another course when will you finish SOLID course ? I love your teaching and please do not get me wrong .❤
@aibardulatov
@aibardulatov 5 ай бұрын
Please Abhilash can you make a same video about threads?
@user-vm9nt9zx2r
@user-vm9nt9zx2r 11 ай бұрын
HI, Abhilash could u make video on Auth2
@uniqName337
@uniqName337 11 ай бұрын
your videos are amazing. one suggestion please don't add the background music.
@shraddhasahu7657
@shraddhasahu7657 Жыл бұрын
Hi sir....
@nitinchoudhary9015
@nitinchoudhary9015 Жыл бұрын
No one is there like selelium express
@mohammadmutawe9783
@mohammadmutawe9783 Жыл бұрын
Wow!! Thanks for sharing
@yatendra__singh
@yatendra__singh Жыл бұрын
Very late uploaded 😢😢
@mohammadmutawe9783
@mohammadmutawe9783 Жыл бұрын
It's never too late
@divakarpandey9094
@divakarpandey9094 5 күн бұрын
Too long 😢 It's all for nothing
Coding Was Hard Until I Learned THESE 5 Things!
7:40
Pooja Dutt
Рет қаралды 1 МЛН
Каха и суп
00:39
К-Media
Рет қаралды 4,6 МЛН
He sees meat everywhere 😄🥩
00:11
AngLova
Рет қаралды 12 МЛН
3M❤️ #thankyou #shorts
00:16
ウエスP -Mr Uekusa- Wes-P
Рет қаралды 14 МЛН
Incredible magic 🤯✨
00:53
America's Got Talent
Рет қаралды 68 МЛН
Liskov: The Liskov Substitution Principle
4:23
Turing Awardee Clips
Рет қаралды 19 М.
Set and HashSet in Java - Full Tutorial
20:43
Coding with John
Рет қаралды 202 М.
.equals() vs. == in Java - The Real Difference
8:48
Coding with John
Рет қаралды 181 М.
Каха и суп
00:39
К-Media
Рет қаралды 4,6 МЛН