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

Поділитися
Вставка
  • Опубліковано 27 гру 2024

КОМЕНТАРІ • 169

  • @SeleniumExpress
    @SeleniumExpress  5 років тому +7

    For step by step explanation on hashcode and equals() in Java, please check out my new playlist by clicking the link below
    ua-cam.com/play/PL3NrzZBjk6m95SR6WzhnOGGCjXZpCoO-k.html

    • @ChongSLee
      @ChongSLee 5 років тому

      i get invalid parameters... is this right url? thanks.

  • @sanketh768
    @sanketh768 2 роки тому +1

    this helped me out with my issue today, thank you ver much

  • @vimalsubha
    @vimalsubha 6 років тому +20

    I like the way you started the problem and slowly decoding...

  • @swapnilshinde8110
    @swapnilshinde8110 3 роки тому

    it,s Really Helpful me this video..........Thanks a lot Sir.

  • @sreenivasl5383
    @sreenivasl5383 Рік тому

    Explained very nicely.. The way of started, the way of required info from api document, different type objects.. 👏

  • @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...

  • @Karthik-y3o4z
    @Karthik-y3o4z 5 місяців тому

    You tooooo have an impeccable knowledge😊😊

  • @AllinOne-et2on
    @AllinOne-et2on 3 роки тому

    I am watching on Sep 2021. Great job bro. ❤️❤️

  • @manojdehran4698
    @manojdehran4698 6 років тому +6

    You are a real coder, otherwise most of the people talks about theory.
    Keep up the good work !!

  • @shanthinis5667
    @shanthinis5667 Рік тому

    Very nice explanation.... Awesome 👍

  • @aakashdetwal9950
    @aakashdetwal9950 3 роки тому

    Your way of explain is understandable it is helpful

  • @niteshpandey8207
    @niteshpandey8207 Рік тому

    That's Amazing I'am not aware about Wrapper class that it having equal and hashcode.

  • @muralimohan7097
    @muralimohan7097 3 роки тому

    The way you are explaining the concept with example is awesome and it clear to understand

  • @PoonamSharma-gy3ky
    @PoonamSharma-gy3ky 3 роки тому

    Really very helpful content with proper explaination

  • @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.

  • @nareshch6454
    @nareshch6454 3 роки тому

    Wonderful explaination brother

  • @mbrajucse
    @mbrajucse 3 роки тому

    Super bro. Nice explaination.👍

  • @tasteanotherbite1265
    @tasteanotherbite1265 2 роки тому

    Amazing explanation 👌

  • @madhavanananthan7077
    @madhavanananthan7077 3 роки тому +1

    Master level explanation, really hats off
    Actually I watched several videos to understand this concept. But this one is 🔥 simply

  • @saranyan3910
    @saranyan3910 3 роки тому

    Wow! Awesome explanation 🙏

  • @ElCanalDelPadrino
    @ElCanalDelPadrino 2 роки тому

    Excellent explanation!!

  • @ajaysuresh3781
    @ajaysuresh3781 3 роки тому

    Very nice clear explanation Sir. Thank you 👍

  • @danceayush8128
    @danceayush8128 3 роки тому

    Now I actually got the point.. Thanks brother 👍

  • @deepikajagadees7996
    @deepikajagadees7996 2 роки тому

    Thank you a lot for the great explanation

  • @letusmeet5427
    @letusmeet5427 4 роки тому

    so super explanation , really it's wonderful explanation. You borned for us only.
    so so sooooo nice of you.. Thank you soooooo much.

  • @pratikalhat9484
    @pratikalhat9484 2 роки тому

    very nicely explained

  • @lordgreat6051
    @lordgreat6051 2 роки тому

    Because map uses hash to target keys! brilliant example thanks

  • @ponsivakumarmanoharan4994
    @ponsivakumarmanoharan4994 3 роки тому

    Good one

  • @priyankaraut9289
    @priyankaraut9289 4 роки тому

    Gud information keep going

  • @sauravsrivastava9019
    @sauravsrivastava9019 2 роки тому

    Good explanation

  • @kumarvijayag
    @kumarvijayag 2 роки тому

    best example, basic point explained, but still should have talked more about equals and hashcode methods

  • @hetalrachh5665
    @hetalrachh5665 4 роки тому

    Amazing and very simple explanation, Thanks !!

  • @1976balakrishna
    @1976balakrishna 3 роки тому

    nice one

  • @macherladevasundaram4928
    @macherladevasundaram4928 4 роки тому

    Very good explanation bro.. Thank you..

  • @atiqulny
    @atiqulny 4 роки тому

    You are a genius

  • @saiadaikappan
    @saiadaikappan 4 роки тому

    Very clear explanation, thank you !!! your voice makes the explanation more interesting.

  • @harit9380
    @harit9380 4 роки тому

    Great Video!! Understood clearly!

  • @DavidCervantesmrclutch
    @DavidCervantesmrclutch 4 роки тому

    Nice video Bro

  • @chloeren9175
    @chloeren9175 2 роки тому

    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?

  • @AtulMishra-rs5os
    @AtulMishra-rs5os 6 років тому +18

    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 6 років тому

      Agreed men

    • @SudhanshuSrivastavaIndia
      @SudhanshuSrivastavaIndia 5 років тому +1

      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...

  • @oussamabr5851
    @oussamabr5851 4 роки тому

    Excellent explanation! Thanks.

  • @somethingforyou891
    @somethingforyou891 5 років тому +1

    Superb explanantion. Thank you

  • @abhinavghosh725
    @abhinavghosh725 4 роки тому +2

    finally someone clearly explained it!

  • @shalabhdixit
    @shalabhdixit 6 років тому +10

    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  6 років тому +2

      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 6 років тому

      @@SeleniumExpress ok. Thank you!

    • @merajulhaque9107
      @merajulhaque9107 4 роки тому

      @@SeleniumExpress Can you please share the link for the complete concept video.

  • @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.

  • @subhashininallapati2080
    @subhashininallapati2080 4 роки тому +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.

  • @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.

  • @kingajable
    @kingajable 4 роки тому

    you doing great job buddy keep it up

  • @bignormalizedgaps
    @bignormalizedgaps 6 років тому +3

    Спасибо! Thank you from Russia!

  • @krishnasingh9111
    @krishnasingh9111 6 років тому +1

    Very help full for beginners thank you :)

  • @krishnasuripaka2480
    @krishnasuripaka2480 4 роки тому

    Super Brother...

  • @salenaluu8477
    @salenaluu8477 3 роки тому +1

    Thank you so much

  • @shubhamraj5184
    @shubhamraj5184 3 роки тому

    Wow thanks 💓

  • @erictang4447
    @erictang4447 5 років тому

    Thank you for explanation. The visual animation is very helpful.

  • @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.

  • @mohanas6697
    @mohanas6697 6 років тому +17

    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 років тому +3

      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 років тому +3

      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 років тому +1

      @@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 років тому +2

      @@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

  • @dsgtechinfo5639
    @dsgtechinfo5639 3 роки тому

    Thanks a lot friend

  • @srilakshmi5922
    @srilakshmi5922 4 роки тому

    simply awesome

  • @techsteering
    @techsteering 5 років тому +1

    Excellent. Thanks for sharing your knowledge.

  • @harshav3902
    @harshav3902 5 років тому

    Thanks for the explanation dude. It helped.

  • @anonymouskunal2748
    @anonymouskunal2748 3 роки тому

    overall conclusion 10:40 thank you sir

  • @Ishnavvulu
    @Ishnavvulu 6 років тому +2

    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 :)

  • @deepar781
    @deepar781 5 років тому +1

    Its good. Keep Posting bro

  • @amitaswar7010
    @amitaswar7010 6 років тому +1

    I like the ending music so much and video too thank you bhai

  • @kanagarathinamannamalai8020
    @kanagarathinamannamalai8020 5 років тому

    Nice Explanation bro.Thanks👍..

  • @commonman8540
    @commonman8540 2 роки тому

    HI Avinash, When we use jpa repository.saveOrUpdate(product);, my product object has 1 lak records, will it accept? Is there any limitation ?

  • @premkirankatinedi4479
    @premkirankatinedi4479 5 років тому

    Wow...this is to the point. Thanks a lot

  • @trendytopics-
    @trendytopics- 3 роки тому

    THANK YOU SO MUCH!

  • @sulavagarwal3561
    @sulavagarwal3561 6 років тому +1

    u got great explanation skills

  • @gauravsharma875
    @gauravsharma875 4 роки тому +1

    How come emp1 and emp2 having the same hashcode? Can someone please help

  • @rthiaga
    @rthiaga 5 років тому +1

    In the hashCode method why 31 is multiplied by 1 and id. We can directly return the id right?

    • @raghavanaliassaravananm1546
      @raghavanaliassaravananm1546 5 років тому +2

      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.

  • @ShubhamGupta-fm7lv
    @ShubhamGupta-fm7lv 6 років тому +10

    I don't know why I didn't see this video earlier. Got this in an interview and I wasn't able to answer.

  • @RiyazParasara
    @RiyazParasara 5 років тому +1

    Great thanks.

  • @premkirankatinedi4479
    @premkirankatinedi4479 5 років тому

    Simply Awesome!!

  • @alittlecoding
    @alittlecoding 5 років тому

    Good job. thanks

  • @kssinfonet2394
    @kssinfonet2394 3 роки тому

    Dear Abhilash sir i have one que. which empoyee object will hashmap put 1st ya 2nd after using hashmap and equal method😊

  • @lux27.42
    @lux27.42 5 років тому

    this video easy to understand :) thankyou so much.

  • @aayush-zw1mx
    @aayush-zw1mx 4 роки тому

    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

  • @JaishriVemuganti
    @JaishriVemuganti Рік тому

    I put the code as you shown in my side and in both cases ham getting size =2

  • @helishah9065
    @helishah9065 5 років тому +1

    Amazing explanation! Thanks a lot :)

  • @tw5529
    @tw5529 3 роки тому

    Great Explanation👌 Thanks a Lot :-) . BTW, which software are you using for making this video?? It looks so attractive 😊

  • @trendingtechnologiesit924
    @trendingtechnologiesit924 6 років тому

    Simply awesome

  • @sonyguptayourdearestsony
    @sonyguptayourdearestsony 6 років тому

    nice good explanation

  • @srikanth29
    @srikanth29 6 років тому +1

    Thank u very much. Very helpful and clear

  • @priyankaraut9289
    @priyankaraut9289 4 роки тому

    Do videos on java framework

  • @damodaranm3044
    @damodaranm3044 5 років тому

    Wow r Ally good .and why don't you make videos in following concept cuz there is no good videos in UA-cam threads collection jsf spring

  • @felixkimutai8478
    @felixkimutai8478 5 років тому

    Great! Thank you.

  • @srinivasang4566
    @srinivasang4566 5 років тому

    Nice

  • @rameshbabu5754
    @rameshbabu5754 5 років тому

    Below my all question are more help full in interview point of view.
    So, Could you please explain below all videos to me

  • @ARI-em6me
    @ARI-em6me 5 років тому

    Very very clear explanation. Plse upload how to upload webproject deployed server

  • @shubhashree3853
    @shubhashree3853 6 років тому

    Can we avoid duplicate object reference by implementing hascode() n equal () methods?

  • @rameshbabu5754
    @rameshbabu5754 5 років тому

    Could you please explain the oops (Abstraction, Inheritance, Encapsulation, Polymorphism ) concepts in java with theory and real examples

  • @vishnupriya80
    @vishnupriya80 4 роки тому

    hi your videos were really helpful. do you have any videos related to regular expressions?

  • @rameshbabu5754
    @rameshbabu5754 5 років тому

    Could you please explain the Internal mechanism of HashSet in java with theory and real time examples

  • @subramanianchenniappan4059
    @subramanianchenniappan4059 5 років тому

    Thanks a lot

  • @Ceecee384
    @Ceecee384 5 років тому

    When you instantiate 2 Employee objects with the same ID, shouldnt it still be considered as 2 seperate objects? Just because both objects have the same ID value, doesnt mean they are equal? For example, 2 car objects can have the same color attribute. So why would we be expecting the hashmap.size to return 1? It should still have 2 objects mapped, no?

    • @nishantbansal9409
      @nishantbansal9409 4 роки тому

      It depends on how your equals method is implemented

  • @peedrap987654321
    @peedrap987654321 6 років тому

    Excellent

  • @rameshbabu5754
    @rameshbabu5754 5 років тому

    Could you please explain the use of Comparable and Comparator in java with theory and real time examples

    • @dhanalaxmi2569
      @dhanalaxmi2569 5 років тому

      Verify durga software videos it is explained thr

  • @rameshgollapudi588
    @rameshgollapudi588 6 років тому

    Very nice

  • @rameshbabu5754
    @rameshbabu5754 5 років тому +1

    Could you please explain the use of String Buffer and String Builder in java with theory and real time examples