Records In Java - Full Tutorial - The Best New Java Feature You're Not Using

How to use Records in Java!
Complete Java course: codingwithjohn.thinkific.com/...
Records are a new concept added to the Java language as a preview feature in Java 14, and in a full release in Java 16. In this intermediate Java programming tutorial, we will talk all about when you would want to use Java records, and exactly how to do it.
If you're confused by records in Java, you're in the right place!
Learn or improve your Java by watching it being coded live!
Hi, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java learners.
Let me know what else you'd like to see!
Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
📕 THE best book to learn Java, Effective Java by Joshua Bloch
amzn.to/36AfdUu
📕 One of my favorite programming books, Clean Code by Robert Martin
amzn.to/3GTPVhf
🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
www.audibletrial.com/johnclean...
🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
bit.ly/3QPNGko
📹Phone I use for recording:
amzn.to/3HepYJu
🎙️Microphone I use (classy, I know):
amzn.to/3AYGdbz
Donate with PayPal (Thank you so much!)
www.paypal.com/donate/?hosted...
☕Complete Java course:
codingwithjohn.thinkific.com/...
codingwithjohn.com

Пікірлер: 537

  • @Mahmoudalkasem1997
    @Mahmoudalkasem19972 жыл бұрын

    The best person on KZread that explains java in such a great way

  • @pavelsakun2308

    @pavelsakun2308

    2 жыл бұрын

    If you didn't see anyone better doesn't mean he is the best ;-) He is good anyway.

  • @Mahmoudalkasem1997

    @Mahmoudalkasem1997

    2 жыл бұрын

    @@pavelsakun2308 this is my opinion and l am free to think whatever I want right ;)

  • @keionvergara7608
    @keionvergara76082 жыл бұрын

    you were the reason i got a 5 on my ap comp sci A exam!! you truly have impacted my education and taught me more than my highschool teacher did in 5 months !

  • @CodingWithJohn

    @CodingWithJohn

    2 жыл бұрын

    Awesome, and congrats!

  • @Reichstaubenminister

    @Reichstaubenminister

    11 ай бұрын

    Funny, 5 would be an E in Germany. Had to think about that for a second.

  • @justinliu7788

    @justinliu7788

    10 ай бұрын

    It’s 5/5

  • @ItIsJan

    @ItIsJan

    10 ай бұрын

    ​@@Reichstaubenministersprach der reichstaubenminister

  • @libertymedicalcommunicatio4908
    @libertymedicalcommunicatio49082 жыл бұрын

    Congrats on almost reaching 100K. This one should put you over the top.

  • @fisch37

    @fisch37

    2 жыл бұрын

    You are correct!

  • @sukusukumar2413

    @sukusukumar2413

    2 жыл бұрын

    Please take one class about scanner class..

  • @AntropomorficznaPersonifikacja

    @AntropomorficznaPersonifikacja

    Жыл бұрын

    Thanks

  • @Nanagos
    @Nanagos2 жыл бұрын

    I recently found out about Records but there are just no good tutorials about it. I'm glad you made one now.

  • @CodingWithJohn

    @CodingWithJohn

    2 жыл бұрын

    Thanks! Yeah there's surprisingly little out there so far. Probably just because it's pretty new.

  • @GreatProgrammerHsin
    @GreatProgrammerHsin2 жыл бұрын

    please never stop making videos, these are so helpful!

  • @iCybqr
    @iCybqr2 жыл бұрын

    Could you do a video on Consumer, Predicate, and Supplier? I mostly understand what they do, but not when to use them.

  • @YtubeUserr

    @YtubeUserr

    6 ай бұрын

    if you are reading this John, please make this video happen! Thanks!

  • @arnddeshives147
    @arnddeshives1472 жыл бұрын

    There is a lot of content like this out there, but you are so much better than the rest in terms of tempo, order, quality and presentation, thank you so much! I started studying CS half a year ago and your videos are 5x quicker at explaining the same thing than my prof. Although sometimes there is some depth missing, but it's good that your videos don't get lost in that, that's what makes it so good. Maybe it would be great if there was a playlist for in depth knowledge as well though.

  • @huskydreaming
    @huskydreaming2 жыл бұрын

    I am advanced in java but it is great to see someone explain it so concise. Amazing explanation on these types of videos. Keep it up!

  • @leeamraa
    @leeamraa2 жыл бұрын

    Quality, effective, efficient and much appreciated content.

  • @pradiptaspointofview1475
    @pradiptaspointofview14752 жыл бұрын

    Explained quite clearly with detailed examples. Excellent tutorial! This is what I needed to start working with Records in Java.

  • @pclclau
    @pclclau2 жыл бұрын

    At 5:00 you mention that Java generates a default, no-arg constructor *even if* you don't create other constructors. That isn't quite true, Java creates a no-arg constructor *only if* you don't create other constructors. This is why your fields get red underlines as soon as you manually create the no-arg constructor, because there would be a way to have final fields that aren't initialized as soon as the object is created. Before you manually created the no-arg constructor this wasn't a problem, because Java wouldn't generate one since you already had the previous one created.

  • @eufraniodiogo50

    @eufraniodiogo50

    2 жыл бұрын

    That's absolutely true, maybe it was just a runtime exception(subclass of Exception) at his speech. lol

  • @KaraSuraDraw1

    @KaraSuraDraw1

    2 жыл бұрын

    I don’t get what you mean. I feel like your comment just justified what he said. Or do you think he meant even if you have other constructors Java always generates a default no-arg constructor? I think he just put it there for visuals of a no-arg constructor. Because i got that what you said from the video.

  • @pclclau

    @pclclau

    2 жыл бұрын

    @@KaraSuraDraw1 He said that Java provides a no-arg constructor no matter what constructor you already have definded. That's not true.

  • @alfasolarenergy

    @alfasolarenergy

    2 жыл бұрын

    When you create an object of the Class two things happes: 1. MEMORY IS ALLOCATED, 2. THE CONSTRUCOR IS CALLED. By default Java offers a 0 argument construcotrs which are 0 for numeric types, and false for boolean and null. The moment we create our impemtation of constructor ( a constructor which initialize fields) the 0 arg one is no longer called.

  • @TechiiEngineer

    @TechiiEngineer

    2 жыл бұрын

    True , if you have created just an args-constructor ; You cant created object as : new Employee(); That means Employee class doesn’t have no arg constructor ; You have to create one.

  • @emilmathew2257
    @emilmathew2257Ай бұрын

    Have been following your videos for a while now. Thank you for the awesome content 😊

  • @sijanbhandari7569
    @sijanbhandari75692 жыл бұрын

    Thanks for teaching me more about records, I was always teaching my fellow programmers about this in my workplace.

  • @randomuserrandom8613
    @randomuserrandom86132 жыл бұрын

    Thank you so much. This was very helpful and the way you explain things makes it so easy to understand them. Keep up the good work, John!

  • @BkSMedia
    @BkSMedia Жыл бұрын

    I've been learning Java in my CS degree for the last three years, I had no idea records were a thing!!! So cool!

  • @CodingWithJohn

    @CodingWithJohn

    Жыл бұрын

    Yep! They're a relatively recent addition.

  • @ccmawil20
    @ccmawil202 жыл бұрын

    Explanation is clean and clear. please publish more videos like this. Thanks

  • @jimjimjimjimjim6572
    @jimjimjimjimjim65722 жыл бұрын

    Nice pace, and super clear, cheers my man

  • @chenchi6623
    @chenchi66237 ай бұрын

    I like the style of teaching, very clear examples and no bs, earned a sub...

  • @mustapharaimilawal8053
    @mustapharaimilawal80532 ай бұрын

    Thanks a lot for doing this tutorial. Clear, easy to follow explanation as always.

  • @shankar7435
    @shankar7435 Жыл бұрын

    Never thought learning Java would be such a pleasure. A decade ago, I was frustrated with the Java Reference book and left learning java and continued with my day job in DB language. Now, I am learning java without any issues with the help of youtube. Thanks to the youtube community.

  • @nischalofchrist
    @nischalofchrist2 жыл бұрын

    Thank you, I've always wanted to learn about Records.

  • @Markki28
    @Markki282 жыл бұрын

    awesome as always, thank you for sharing man, I am familiar with records but I'm not aware that I can do specific field validations directly into it, that's very useful thanks man

  • @katisbetter2952
    @katisbetter29522 жыл бұрын

    Keep up with the good work, you’re helping a lot of people 🙏🏻

  • @simonrozendal7542
    @simonrozendal75422 жыл бұрын

    Hi John. Even when i write Java programs quite a while, i still learn new thing from you. Thank you, you are presenting good Java content. Kind regards, Simon Rozendal.

  • @mastershonobi110
    @mastershonobi1102 жыл бұрын

    Thanks John!!! Always looking for ways to improve and writing clearer/better code.

  • @mastershonobi110

    @mastershonobi110

    2 жыл бұрын

    Side Note…are you using Java 17 or 16? B/c “records” is not supported in Java 11.

  • @sameersafi6128
    @sameersafi61282 жыл бұрын

    The way of teaching is totally different.. thank you so much for the deep knowledge that you are sharing... kindly make tutorial on stream api in future

  • @Jody-nf2bz
    @Jody-nf2bz Жыл бұрын

    Very well explained, readable size text, excellent class! Thank you!

  • @argonwheatbelly637
    @argonwheatbelly637 Жыл бұрын

    Guitars 🎸, drums 🥁, and programming. 💻 Yep! You're definitely part of my tribe. Excellent video! Keep it up.

  • @RamGorre
    @RamGorre2 жыл бұрын

    That's an awesome no BS explanation. Too good.

  • @tuna5395
    @tuna5395 Жыл бұрын

    Thanks bro you helped with my project !

  • @olivierbegassat851
    @olivierbegassat8518 ай бұрын

    Your exposition is always so direct and simple. I love it 🙂

  • @AbdelhameedGamal-ki7th
    @AbdelhameedGamal-ki7th5 ай бұрын

    So simple and clear explanation. I really appreciate your help.

  • @raz0229
    @raz02292 жыл бұрын

    You are so underrated! Hope you reach 1 mil subs soon

  • @antonkimberg8914
    @antonkimberg89142 жыл бұрын

    Hi John, Thank you for your superb content. Me and other group of people from Estonia are learning Java and your channel helps us to understand hard material in a simple way. Could you please make a video tutorial about streams in future? Thank you in advance, Tony

  • @Naimadmdp
    @Naimadmdp Жыл бұрын

    Nice content mate, thanks for share!!!

  • @evagor730
    @evagor730 Жыл бұрын

    Wonderful explanation! Thank you! Shorty and clear)

  • @RicardoSilvaTripcall
    @RicardoSilvaTripcall2 жыл бұрын

    Great explanation !!! Congrats ....

  • @MrLuMax5
    @MrLuMax52 жыл бұрын

    Great video. Especially for those who know the basics and are interested in new Java Features after J11. Keep these up!

  • @mohamedsaleh5970
    @mohamedsaleh59702 жыл бұрын

    You helped me understand concepts that was difficult to understand on my own.

  • @electricant55
    @electricant552 жыл бұрын

    Except for that neat overriding constructor, it seems like Lombok is still a more useful option, unless you can put annotations on the fields declared in record for things like JPA or JSON serialization

  • @Darya-pu6ik

    @Darya-pu6ik

    2 жыл бұрын

    what is Lombok?

  • @ThiagoHenriqueDS

    @ThiagoHenriqueDS

    2 жыл бұрын

    @@Darya-pu6ik It's a library that allows you to use annotations in order to create things like getters, setters, equals methods, etc. For example, instead of write getters and setters you just use the annotation @Data, @Getter or @Setter above a constructor: @Getter @Setter public Car(String color, String name) { }

  • @Darya-pu6ik

    @Darya-pu6ik

    2 жыл бұрын

    @@ThiagoHenriqueDS thanks, looks helpful!

  • @shivk498

    @shivk498

    2 жыл бұрын

    Lombok is indeed very useful but it still a third party plugin. Java is usually known for its cumbersome syntax but such awesome improvements like records would make java lovers more excited.

  • @pavelsakun2308

    @pavelsakun2308

    2 жыл бұрын

    Seeing comments like this makes me think other devs are spending a lot of time to generate POJOs/DTOs and that's hardly true. That kind of objects is being written once and the rest 99+% of time is spent for writing business logic, so even with what vanilla java and IDEs are providing I do not see HUGE problem of implementing them without record/lombok. The only exception here is readability, but...do you really often open classes named '*DTO" for reading? I really doubt.

  • @KarolKasperek
    @KarolKasperek Жыл бұрын

    u have the best java keyword's tutorials, ty

  • @sandunicula6185
    @sandunicula61852 жыл бұрын

    Great presentation! Thanks!

  • @lucashenrique6076
    @lucashenrique60762 жыл бұрын

    Thanks for the Video John! Greetings from Brazil 😉

  • @maneshipocrates2264
    @maneshipocrates22642 жыл бұрын

    Thanks alot John. This talk should be included in the official doc.

  • @bischoffdev
    @bischoffdev2 жыл бұрын

    I thought I knew all about records (and I am using those extensively) but this is the first time I heard about the compact constructor! Thanks a lot!

  • @B-Billy
    @B-Billy11 ай бұрын

    That's a really good teaching... Thanks 🎉

  • @longtran12345678
    @longtran123456782 жыл бұрын

    your videos really help me to focus on Java again :)

  • @eperrone
    @eperrone2 жыл бұрын

    Not a Java developer but I have to read Java and Groovy all the time. Your videos are great background to help me understand what I’m looking at. Great stuff.

  • @davidfernandotorres3484
    @davidfernandotorres34842 жыл бұрын

    Amazing bro! Thanks for the info

  • @JorgetePanete
    @JorgetePanete2 жыл бұрын

    Perfect tutorial, much appreciated!

  • @RahulSingh-qe4sw
    @RahulSingh-qe4sw Жыл бұрын

    Thank you so much , explaination was very nice.

  • @jaspreet821
    @jaspreet8218 ай бұрын

    Great episode my man!! 😮😮

  • @Atom-Mercury
    @Atom-Mercury10 ай бұрын

    Very well explained. Thank you kindly.

  • @PratikKumar42
    @PratikKumar422 жыл бұрын

    Great video, these really helps alot.

  • @hunelysium
    @hunelysium Жыл бұрын

    Hello John, it's always great to listen to your explanations on Java! Thank you for your valuable wisdom!! On a side note, noticed your voice and the way you talk has changed since you become a father :) Hope you and your family well during this different times! Keep making thus great videos, always love watching them!

  • @bouaddiismail
    @bouaddiismail2 жыл бұрын

    great lesson as always , grettings from Morocco

  • @givemepepsipls536
    @givemepepsipls5362 жыл бұрын

    he best person on KZread that explains java in such a great way

  • @fazithfouseen1548
    @fazithfouseen15482 жыл бұрын

    Hi John, Please upload Microservices and spring boot tutorials as well

  • @anantharamu80
    @anantharamu80 Жыл бұрын

    Love this. Very informative.

  • @chacha-bm4jc
    @chacha-bm4jc2 жыл бұрын

    Thanks a lot John! Would be there any video about sealed classes? It is also quite cool feature

  • @haidaraibrahim9195
    @haidaraibrahim91952 жыл бұрын

    I've watched all of your videos and they r really really helpful and easy to understand, seriously.. u're an amazing teacher and I wish all success for u and ur channel. Small demand: I'd like to learn about Streams in ur way the next tutorial, if that's fine, however, any tutorial u make wod be awesome. Thx man, you're LaJend (J refers to "Java legend"🙂)

  • @frankjuuh
    @frankjuuh2 жыл бұрын

    Love you, John. Best teacher.

  • @matiasmoresi5040
    @matiasmoresi5040 Жыл бұрын

    Mindblown by this feature!

  • @MortenSlottHansen
    @MortenSlottHansen10 ай бұрын

    Nice and precise explanation without any fuzz 🎉

  • @andres98
    @andres982 жыл бұрын

    I was waiting for this video so badly :))

  • @bacon37460
    @bacon374602 жыл бұрын

    Nice feature, thanks John for sharing it with us.

  • @kirankumarsukumar
    @kirankumarsukumar Жыл бұрын

    Omg. You are so amazing at teaching. Thanks Master Yoda

  • @raoufbenabdelwahed6362
    @raoufbenabdelwahed636211 ай бұрын

    well explained as usual !

  • @jaimesastre6393
    @jaimesastre63932 жыл бұрын

    really cool!!! Spring had some simplification, but here it's much better and has also interesting options! Thanks 👍👍

  • @Giorgi.Japiashvili

    @Giorgi.Japiashvili

    Жыл бұрын

    What do you mean by the Spring simplication?

  • @ting-yuhsu4229
    @ting-yuhsu42292 жыл бұрын

    This is amazing! Thank you :D

  • @ayed-al-nator
    @ayed-al-nator Жыл бұрын

    Beautiful video 💚 thank you 😊

  • @WisomofHal
    @WisomofHal2 жыл бұрын

    Wow, awesome video! There are many ways I can think of to use Records.

  • @budiardjo6610
    @budiardjo66104 ай бұрын

    after i am learning about memory management, stack and heap and jvm internals i could really understanding this properly what a powerfull feature

  • @user-qb3ck7cq3k
    @user-qb3ck7cq3k11 ай бұрын

    Thank you brother!

  • @djpharaohoftime3200
    @djpharaohoftime320011 ай бұрын

    Interesting feature well explained thank you.

  • @vladimirspasov5591
    @vladimirspasov55912 жыл бұрын

    Great explanation

  • @hbfl3x50
    @hbfl3x50 Жыл бұрын

    Very informative 👏

  • @ayberkctis
    @ayberkctis2 жыл бұрын

    Hey John! If i knew Records before, i would use them in my previous task in my company because they fitted my task perfectly! Thank you for your effort :)

  • @danigonzalez6231
    @danigonzalez62312 жыл бұрын

    Thank you sooooo much!

  • @tanacing347
    @tanacing34726 күн бұрын

    Gracias John!!!

  • @Speiger
    @Speiger2 жыл бұрын

    Looks like Records are like Lombock. I assume they have the same pitfalls you can run into if you are not careful. But this tutorial was really nice, I haven't touched these yet, but i see for myself already tons of usecases for this. Especially for like singleton function classes, where you have your builder and then the object that executes said code. Keep up the work!

  • @hellowill

    @hellowill

    2 жыл бұрын

    It's not as powerful as Lombok unfortunately

  • @Speiger

    @Speiger

    2 жыл бұрын

    ​@@hellowill But it does not have the same critical performance pitfalls like Lombok has. And to give context. In a performance sensitive context lombok has the ability to destroy your performance just based on how the variables are compared in a hashcode/equals function where the order can be important.

  • @hellowill

    @hellowill

    2 жыл бұрын

    @@Speiger Ah right. I guess I dont focus too much on performance critical workloads. I do wish records had better support for builders or so called 'withers'.

  • @Speiger

    @Speiger

    2 жыл бұрын

    @@hellowill Lets put it that way. For people who use lombok its not a great option. For everyone else it is a good way to reduce code and it does reduce the Licensing hell.

  • @emanueltrandafir8756

    @emanueltrandafir8756

    Жыл бұрын

    @Speiger, @Will - I personally believe java records and lombok are different features that can be used for different things. Records are similar to Lombok's @Value classess, indeed - but Lombok has a lot of other features to offer and it allows much more flexibility.

  • @MrBrackets
    @MrBrackets Жыл бұрын

    great video, thank you!

  • @Wallasmod
    @Wallasmod2 жыл бұрын

    Excellent video

  • @javalady
    @javalady21 күн бұрын

    Wow that was cool, thank you 😍

  • @cverde1234
    @cverde12342 жыл бұрын

    This is really similar to records in C#. We don't have compact constructors though. I think compact constructors are really neat.

  • @BillyCha00
    @BillyCha002 жыл бұрын

    Hi John, you are the best!! please upload Microservices and spring boot tutorials :)

  • @ChristienChapman
    @ChristienChapman2 жыл бұрын

    Good tutorial. I will use this from now on, much more simple way to do the same thing. God bless you.

  • @kesavenvulliamay4637
    @kesavenvulliamay46372 жыл бұрын

    Very Informative

  • @hakkcancakmak6275
    @hakkcancakmak62752 жыл бұрын

    Thanks for this video

  • @sovrinfo
    @sovrinfo2 жыл бұрын

    Thank you a lot!

  • @TakeshySun
    @TakeshySun2 жыл бұрын

    @ Coding with John , Hi, could you please record a video about Java 8 features like Optional and Streams. It will be so wonderfully. And big thank you for short and really useful videos!

  • @yonneltg1150
    @yonneltg11502 жыл бұрын

    Perfectly explained.

  • @overrim13
    @overrim132 жыл бұрын

    Thank you for explaining some unexplored topic

  • @FLStudioTutorialz
    @FLStudioTutorialz2 жыл бұрын

    Awesome. Thanks.

  • @gasgeek434
    @gasgeek4342 жыл бұрын

    thank you so much for your videos

  • @kenway346
    @kenway3462 жыл бұрын

    I randomly stumbled upon this video and ended up subscribing to your channel :)

  • @sanuretaroro3281
    @sanuretaroro32812 жыл бұрын

    Your explanation is beautiful

  • @arielfranco8251
    @arielfranco8251 Жыл бұрын

    Great tutorial

  • @christianrodier3381
    @christianrodier33812 жыл бұрын

    That is very useful!

  • @DevPieter
    @DevPieter2 жыл бұрын

    This is sick! I wanted to find this sooner 😥