Let's Understand famous Java interview Questions | Comparable vs Comparator with Example

Sdílet
Vložit
  • čas přidán 9. 07. 2024
  • In this video we will learn what is difference between Comparator and Comparable in java with practical example.
    00:00 Introduction to Video
    01:07 Understand The Context : About Collection and Group of Objects
    04:56 Understanding of Sorting Objects in Collection[Comparator and Comparable]
    Telegram Link for Doubt: t.me/learncodewithdurgesh
    Important Videos:
    ➡️React JS with Project : • 🔥 🔥 Complete React Js ...
    ➡️Learn JDBC in one video: • JDBC Crash Course in 1...
    ➡️Learn Python in One Video: • Learn Python in One Vi...
    ➡️Learn HTML in one video: • Jquery in one video in...
    ➡️Learn HTML form in one video: • Jquery in one video in...
    ➡️Learn JavaScript in one videos: • Learn JavaScript in O...
    ➡️Learn Form Validation using javascript and jquery: • Form Validation using ...
    ➡️Learn CSS in one video: • Jquery in one video in...
    ➡️Jquery in one video: • Jquery in one video in...
    Kotlin is one video: • Kotlin | Learn Kotlin ...
    ➡️Complete Python Project - CZcams downloader in one video: • Jquery in one video in...
    Important Playlist:
    ➡️Spring Boot Tutorial with Project : • Spring Boot Tutorial i...
    ➡️Spring MVC Tutorial: • Spring MVC Tutorial St...
    ➡️Complete Spring Framework Tutorial: • Spring Framework Tutor...
    ➡️Hibernate Tutorials: • Hibernate Tutorial for...
    ➡️E-Commerce Project using Java: • E-Commerce Project usi...
    ➡️AWS Free Java Hosting Playlist: • AWS Hosting Tutorial |...
    ➡️Hibernate Tutorial Playlist: • Hibernate Tutorial for...
    ➡️Learn Technology in One Vides: • Learn in one video : C...
    ➡️Programming Tips for Programmers: • Coding Tips and Discus...
    ➡️Complete Python for Beginners: • Complete Python Tutori...
    ➡️Important Python Projects: • Python Projects in Hindi
    ➡️Complete Servlet & JSP : • Servlet and Jsp (Serve...
    ➡️Complete JDBC ( Java Database Connectivity) : • JDBC(Java Database Con...
    ➡️Complete Java Project : TechBlog: • Full Java Advance Pro...
    ➡️Java Swing Projects: • Java Projects for begi...
    ➡️Java Core Concepts: • Java Core Tutorial
    ➡️Kya aap Jante hai Series: • kya app jante hai : s...
    Important Links:
    👉Official Website (Source Code): learncodewithdurgesh.com/
    👉Telegram Discussion Group: t.me/learncodewithdurgesh
    👉Follow me on Instagram: / durgesh_k_t
    👉Follow on Facebook / learncodewithdurgesh
    Disclaimer:
    All videos are for educational purposes and use them wisely. Any video may have a slight mistake, please take decisions based on your research. This video is not forcing anything on you.

Komentáře • 110

  • @vedpandey2951
    @vedpandey2951 Před 2 lety +31

    Yes please make a series of Java interview questions with answer.

  • @share_analysis
    @share_analysis Před rokem +1

    Finally ,I understand the detail concept of Comparator & Comparable. thankyou so much sir.

  • @eagle-tips-ff564
    @eagle-tips-ff564 Před 2 lety +8

    Thank you sir may God make your channel of 1 million subscribers because youtube tutors like you tech us that things that we can never learn by paying Thanks again❤️

  • @kshitijbansal3672
    @kshitijbansal3672 Před rokem

    Sir, bhut sare videos dkehle iske, pr apne jo explain kia hai, vaisa clear duniya mai koi ni kr sakta...hath jod kr thanks apko

  • @soumyadebbasu7882
    @soumyadebbasu7882 Před 2 lety

    Thanks Sir. Please provide more of such interview videos!

  • @rohanpatel3115
    @rohanpatel3115 Před rokem

    hello bro what should i learn for java gui for android , do we have to design like html and css through code ? i have seen video where they just have select the view like button etc.

  • @crackit5472
    @crackit5472 Před 2 lety +1

    Yes sir we need a series of interviews for java

  • @payalpanjwani5332
    @payalpanjwani5332 Před rokem

    Thankyou so much! Very well explained. ✌

  • @mdshabu0901
    @mdshabu0901 Před 5 měsíci

    mast laga sir apka teaching style aur samjhane ka tarika thank You Sir

  • @faizanabbas839
    @faizanabbas839 Před 2 lety

    We can also say comparable use for default natural sorting order and comparator for custumomized

  • @pranshu_bisht
    @pranshu_bisht Před rokem

    Sir u r incredible😊 Thanks for clearing my concepts

  • @photo_lab4095
    @photo_lab4095 Před 2 lety

    very helpful for interview point of view

  • @ganavin3423
    @ganavin3423 Před 16 dny

    great video. thanks .

  • @raghavgupta6446
    @raghavgupta6446 Před rokem

    Thanks a lot for clearing this confusion

  • @ajeetchouksey1167
    @ajeetchouksey1167 Před rokem

    Best Ever video, easy explanation
    No one gives this in depth insight in simple language, Thanks @LearnWithDurgesh

  • @riyamaji8350
    @riyamaji8350 Před 3 měsíci

    So clearly explained

  • @vikas_roy_v1
    @vikas_roy_v1 Před 2 lety +3

    I had been asked also this question, Make a video on 'serialization' also sir this is also very frequent asked question in interview

  • @mayankshrivastava9046
    @mayankshrivastava9046 Před 2 lety

    yes yes, Yes please make a series of Java interview questions with answer.

  • @kumarinidhi90
    @kumarinidhi90 Před 2 lety

    Thanks a lot sir.. Nicely explained.... Please make a playlist of java interview questions.

  • @dhiranshukeswani8822
    @dhiranshukeswani8822 Před rokem +1

    Hi Durgesh
    Thanks a lot for the valuable content you share,
    Could you please make one video on concurrent hashmap + locking mechanism

  • @pahadsingh3709
    @pahadsingh3709 Před rokem

    Ha sir ji ese video chahiye

  • @miteshbarnwal8239
    @miteshbarnwal8239 Před rokem

    You explain difficult concepts in a very simple way

  • @YogeshPatil-xs4sw
    @YogeshPatil-xs4sw Před 6 měsíci

    @Thank you Durgesh, it is an excellent explanation of Comparator and Comparable, please add steam of Comparator and if possible Comparable

  • @saritaprasad4295
    @saritaprasad4295 Před 2 lety

    You are great Sir!!!!

  • @yaqubfarooqui8431
    @yaqubfarooqui8431 Před 4 měsíci

    Most wanted channel learnWithDurgesh in social media.

  • @anshgandhi5757
    @anshgandhi5757 Před 2 měsíci

    Thank you so much bhai
    I had doubts regarding this one since long time
    really helpful

  • @RahulPatel-uh6zk
    @RahulPatel-uh6zk Před 2 lety

    Very helpful video 🙏🙏🙏🙏🙏❤️❤️❤️❤️❤️❤️❤️

  • @misalmncomps
    @misalmncomps Před 2 lety

    yes sir makes the interview questions...

  • @ashishdhule6797
    @ashishdhule6797 Před 2 lety

    Yes make a series of interview questions with answers

  • @swapniljagatap3533
    @swapniljagatap3533 Před rokem

    Thank you so much

  • @debiprasaddash654
    @debiprasaddash654 Před 2 lety

    Yes sir please make a interview series

  • @ashishkumarsrivastav9106
    @ashishkumarsrivastav9106 Před 10 měsíci +1

    Great learning

  • @mdumarreza3072
    @mdumarreza3072 Před 2 lety

    Thank you so much sir

  • @kumardebyashish8295
    @kumardebyashish8295 Před 2 lety

    we need a series of interviews for java . please make a series

  • @tejasvinikalpande6715
    @tejasvinikalpande6715 Před 2 lety

    Thanku so much for video ,it really helpfull
    Plz make video on java interview question

  • @kiranthakur5046
    @kiranthakur5046 Před měsícem

    Thanks bro😊

  • @CompIT0597
    @CompIT0597 Před rokem

    Thank you sir

  • @aakashdetwal4866
    @aakashdetwal4866 Před rokem

    very nice explanation

  • @tonmoykhan5737
    @tonmoykhan5737 Před 2 lety

    Thank you

  • @abhishekpawar114
    @abhishekpawar114 Před 2 lety +1

    Sir we want these type of example more Please do sir....

  • @dipankargarai2727
    @dipankargarai2727 Před 2 lety

    Thank you sir 😊

  • @navneettripathi2110
    @navneettripathi2110 Před 2 lety

    Have seen many comparable and comparator videos. M sure this is best. But u could have included the reverse sorting or multiple sorting ways also.

  • @shreyasvaghasia7175
    @shreyasvaghasia7175 Před rokem

    wow, so well explained , make videos in all imp topics sir pls

  • @nileshgitte9279
    @nileshgitte9279 Před 2 lety

    Its very important for interview session please make some video on interview

  • @Jk-tr1fb
    @Jk-tr1fb Před 2 lety +1

    Sir, I have faced this topic in my last interview

  • @AshishSingh-rx4sq
    @AshishSingh-rx4sq Před 2 lety

    Great

  • @mdshadabalam6453
    @mdshadabalam6453 Před 2 lety

    Good one.

  • @Rohit-dj2lm
    @Rohit-dj2lm Před 2 lety

    Sir how to fix this problem" communication link failure " in eclipse

  • @bhuvneshkumarsharma7671

    thanks sir

  • @RandomClicksBy
    @RandomClicksBy Před 2 lety

    Sir plz continue this series

  • @indrajeetjyoti9020
    @indrajeetjyoti9020 Před 2 lety +1

    make videos on on concurrent multithreding like executor framework and java 11 features

  • @mindbehaviour9195
    @mindbehaviour9195 Před 2 lety

    Durgesh bhai is GOAT❤️💖💕

  • @TheChi100
    @TheChi100 Před 2 lety

    If there is another list inside the emp object. Then how we will compare it.

  • @sandeepnalawade6886
    @sandeepnalawade6886 Před 8 měsíci

    Please make video on String vs String buffer vs String builder with example.

  • @vivekbhore5722
    @vivekbhore5722 Před 2 lety

    THANK U SIR

  • @priyankabachhav5315
    @priyankabachhav5315 Před rokem

    Thank you so muchhh sir, for this informative concept.. I was too confused in between comparable and comparator and watching videos on CZcams makes more confusion in my mind.. Like where to implement comparable when to call, how to print by using StringTo, exact difference between comparable n comparator.. Now I am clear with everything like from basic.. Bus mujhe voh (o1.marks - o2.marks); kaise run hota samjha naii I mean kaise compare hota kon chota kon bada n running process samjhi nai.. Baki sab clear

    • @sabkaBaap007
      @sabkaBaap007 Před rokem +1

      When - value is returned then it means the object 2 is greater than the object 1 and when + value is returned then it means the object 1 is greater than object 2, there is nothing more than that in it.

    • @sabkaBaap007
      @sabkaBaap007 Před rokem

      It's common sense, I mean if you subtract two values and you get negative results then it is obvious that the value one was smaller otherwise why would you have gotten a negative value as the result?

  • @purushottamshisode3661

    great make series on this

  • @ketank6864
    @ketank6864 Před rokem

    Amazing❤❤❤❤❤❤

  • @sachinmankotia2291
    @sachinmankotia2291 Před rokem +10

    Most appropriate answer when to use Comparable and when to use Comparator is :
    If object class (on which you want to do sorting ex : Emp.java is this video) is in your control, then you can use Comparable.
    If object class is not in your control, means you are using some 3rd party API to get data, or you are some library, it means you cant modify code of that object class, the you can use Comparator interface.

  • @rohitsingh2k
    @rohitsingh2k Před 2 lety

    please make more such videos bhaiya thank you.👦🏻

  • @sagarghodekar5745
    @sagarghodekar5745 Před 2 lety +1

    Sirji plz make video on how treemap works internally. Java

  • @mursalimansari1558
    @mursalimansari1558 Před 2 lety

    Sir please make video on hashcode and equals internal implementation

  • @shaifalisrivastava951

    Please make the videos on Comparator and Comparable..

  • @nivesharyal70
    @nivesharyal70 Před 2 lety

    How to sort string in comparable and long in comparator?

  • @borntocode555
    @borntocode555 Před rokem

    Love diz vdeoo

  • @teluram8760
    @teluram8760 Před 2 lety

    Yes Sir Please make some releted vdo

  • @HaiderAli-xy9wb
    @HaiderAli-xy9wb Před 8 měsíci

    Please also make video on hibernate,Spring Boot, microservices interview question and answers

  • @avinashsahu8057
    @avinashsahu8057 Před rokem

    Please make a series of java interview questions

  • @udaypatil7195
    @udaypatil7195 Před 2 lety

    Sir Please make the series of interview questions

  • @shivampathak1405
    @shivampathak1405 Před rokem

    east or west Durgesh bhaiya is the best

  • @SandeepKumar-so2st
    @SandeepKumar-so2st Před 2 lety

    Continue sir

  • @Iimran786
    @Iimran786 Před 10 měsíci

    What is mean by current object and Emp Obj in this compare To method ,you can focus on this by taking example ...sir

  • @ghosh9390
    @ghosh9390 Před 2 lety

    Plz series of interview questions

  • @All_In_786
    @All_In_786 Před 2 lety +2

    I tried in the interview, the interviewer gave me conceptuals questions and i was not selected...
    Thank you Durgesh Bhaijaan for providing such types of videos

  • @asifahmed4313
    @asifahmed4313 Před rokem

    please make a video on singleton class

  • @yashjadhav6157
    @yashjadhav6157 Před rokem

    Bro can you tell me how we use this methods in quiz. Means if i want to prepare a mcq type quiz how should we apply these methods to compare options to answer and this is how we get marks as well.. so can you please make video on this please ?

  • @palakgupta2959
    @palakgupta2959 Před 2 lety +3

    Sir can you please make this video using java 8... most of the interviewers ask this nowadays how to use comparator, comparable using java 8

    • @sabkaBaap007
      @sabkaBaap007 Před rokem +1

      By using Java 8 all you want is to have lamba functions for overriding the functions of this comparable and comparator function interface.
      Else there is no difference.
      Lamba functions are pretty easy to understand.

  • @mayankkhajure3398
    @mayankkhajure3398 Před 2 lety

    Please make one more project on java using servlet and jsp

  • @yatendra__singh
    @yatendra__singh Před 2 lety

    Bhaiya ,pls Java interview series for the experience

  • @ajeetchouksey1167
    @ajeetchouksey1167 Před rokem

    Please make java interview questions series

  • @suchetapawar7540
    @suchetapawar7540 Před 2 lety

    Can we compare multiple fields in one call, something like collection.sort(emps , new IdCompare , new name Compare)
    Is there any alternative way to compare multiple fields in one call?

    • @sabkaBaap007
      @sabkaBaap007 Před rokem +2

      There's no point in comparing multiple fields, just think about that, at any given time you'll have to use one field only if you want to sort. For example how can you sort something by both name and id?
      Either you'd want that to be sorted by name or by id.

  • @neeleshmohanty7380
    @neeleshmohanty7380 Před 2 lety

    Please make series

  • @umeshtiwari3057
    @umeshtiwari3057 Před rokem

    Please explain compareTo and comparator with one more example.

  • @Vikas-yo3jj
    @Vikas-yo3jj Před 2 lety

    Please make video on java project in intellij idea please bro

  • @palashpullarwar2581
    @palashpullarwar2581 Před 2 lety

    Bhai ""serializable"" concept pe video bana do please... Asaan bhasha me.

  • @VishalSingh-uw4ne
    @VishalSingh-uw4ne Před rokem

    Supb

  • @elfish_aru
    @elfish_aru Před 2 lety

    can you please make a series on kafka

  • @syedfaizan5841
    @syedfaizan5841 Před 4 měsíci

    ❤❤❤

  • @java8992
    @java8992 Před 2 lety

    Sir logical question kaisa puchha jaata hai ...uska v video upload kariyega naa aap

  • @sudhanshukumar8404
    @sudhanshukumar8404 Před rokem

    one video for equals and hashcode also..

  • @AnilPatel-ox1jw
    @AnilPatel-ox1jw Před 2 lety

    Spring security par topic wise video bana sakte hai kya

  • @vishalsonwane4374
    @vishalsonwane4374 Před 2 lety

    How can I connect with you?

  • @sanjeevpandit7305
    @sanjeevpandit7305 Před rokem

    Comparator with name sorting is not working

  • @baibhavkumar4743
    @baibhavkumar4743 Před 2 lety

    Bhai interview video banóo

  • @swastinsahoo2397
    @swastinsahoo2397 Před 2 lety

    Class main apna khuda ka custom sort karna hoga toh apko compareable ko implement karna padega .

  • @prateekkk4880
    @prateekkk4880 Před rokem

    Not understood the concept of Comparator

  • @mohammedqhuram6901
    @mohammedqhuram6901 Před 5 měsíci

    allah tumhe islam ki toufeeq de.

  • @rraajjeesshh06279
    @rraajjeesshh06279 Před 9 měsíci

    Such a poor explanation, didn't understood

    • @GeekyCoder170
      @GeekyCoder170 Před 5 měsíci

      Such a poor brain 🧠 couldn't understand such simple logic

  • @anubhavsingh2916
    @anubhavsingh2916 Před rokem

    Can any one explain me this “this.empid - o.empid ”

  • @Neha-il3xi
    @Neha-il3xi Před 3 měsíci

    Thanks sir😍