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 !
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.
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.
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.
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.
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.
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.
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
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.
Hey man, this tutorial on Java Records is good! You broke it down so clearly, the basic parts makes sense. Thanks a lot for this awesome content! Edit : Understood 50% of he video clearly and the rest 50% a little bit....revisiting Java...and Learning..
I cannot believe I completed many courses and projects in Java without using this 😔🤯 My goodness, think of the time I could've saved! Thank you for making this video. It's so engaging, informative, and very easy to understand.
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
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.
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 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.
@@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'.
@@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.
@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.
@ 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!
Tip: If you want to store mutable objects in records: public record EmployeeRecord (java.util.concurrent.atomic.AtomicReference name, int employeeNumber) {} /* Here, _only the value of AtomicReference name_ (a String) is mutable; the value can be changed with employeeRecord.name().set("John"); and can be gotten with employeeRecord.name().get(); */ (or) import java.util.concurrent.atomic.*; public record EmployeeRecord (AtomicReference name, AtomicInteger employeeNumber) {} /* Here, _both_ the values stored by name and employeeNumber (String and _int_ respectively) are mutable. The value of employeeNumber can be changed by employeeRecord.employeeNumber().set(x); (x must be an int or an Integer (if it is an Integer, it will be unboxed)) and can be gotten with employeeRecord.employeeNumber().get(); */ /* FAQ: employeeRecord.employeeNumber().get() returns a variable of type int (may autobox to Integer). If employeeNumber is to be directly of type Integer, it should be declared as java.util.concurrent.atomic.AtomicReference employeeNumber . */
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 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) { }
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.
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.
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!
Hey John. I am from Iraq, at first I would like to tell you about. Your way of explanation is wonderful, and I study programming as a specialist and understand you, but it is possible to ask me to do the Arabic translation feature because some of the sentences are somewhat difficult for him, I do not understand them correctly and I want to continue with you Thank you 💗💗
Holy crap, how have I never heard of this? No Java TH-camr that I've came across has ever mentioned that records even exist. I've always thought they were similar to annotations, so I've never used them. This removes so much redundant boilerplate from typical one use-data storage classes.
❤❤ at the end of the video, as a bonus, if we were to create non-cononical constructors, they would have a strict rule that a constructor wouldn't normally have, which is that they have to call the cononical constructor in the end whether directly using one " this()" statement or multiple "this()" statements in case there were multiple non-cononical constructors.
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 :)
Well...wish I knew this a few years ago...I should really keep up to date with new features. Just reading an article once in a while might save me a lot of work. I love how the fields "getter" methods don't start with "get". I've always hated that (3 extra letters to type and doesn't fall in neatly alphabetically with the other methods).
First thing got in mind is use this for DTOs, but knowing inheritance is not allowed, I dont see use case for records. Getters/setters/constructors and others can be generated by your IDE, thus there's lombok ☺. Anyway thnks concise demo
This is great! I learned a lot from this video. But it left me wondering which versions of Java have records. Also, what about records that have many fields? Are records compatible with the builder pattern recommended for constructors with more than four or so parameters? Keep up the good work, John!
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
That's similar to class declaration in Scala, except that there you can simply specify var or val in front of field name to make it either mutable or immutable. Or make it a case class with immutable fields by default. But in Scala, there is no need for that "compact constructor" because you can write any validation code directly inside the class body.
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"🙂)
The best person on TH-cam that explains java in such a great way
If you didn't see anyone better doesn't mean he is the best ;-) He is good anyway.
@@pavelsakun2308 this is my opinion and l am free to think whatever I want right ;)
I prefer Telusko
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 !
Awesome, and congrats!
Funny, 5 would be an E in Germany. Had to think about that for a second.
It’s 5/5
@@Reichstaubenministersprach der reichstaubenminister
I recently found out about Records but there are just no good tutorials about it. I'm glad you made one now.
Thanks! Yeah there's surprisingly little out there so far. Probably just because it's pretty new.
Could you do a video on Consumer, Predicate, and Supplier? I mostly understand what they do, but not when to use them.
if you are reading this John, please make this video happen! Thanks!
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.
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!
Congrats on almost reaching 100K. This one should put you over the top.
You are correct!
Please take one class about scanner class..
Thanks
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.
I've been learning Java in my CS degree for the last three years, I had no idea records were a thing!!! So cool!
Yep! They're a relatively recent addition.
please never stop making videos, these are so helpful!
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.
That's absolutely true, maybe it was just a runtime exception(subclass of Exception) at his speech. lol
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.
@@KaraSuraDraw1 He said that Java provides a no-arg constructor no matter what constructor you already have definded. That's not true.
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.
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.
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
Guitars 🎸, drums 🥁, and programming. 💻 Yep! You're definitely part of my tribe. Excellent video! Keep it up.
Quality, effective, efficient and much appreciated content.
People like you make much easier to live in the Software Engineering world :)
Thanks bro you helped with my project !
Just wow John, you are awesome. Clear voice. Thank you so much...
Very elaborate and to the point explanation, thank you!
This is something new for me and this video has full of information, every single sec is worth it, Thanks John 😊
I like the style of teaching, very clear examples and no bs, earned a sub...
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.
Thanks alot John. This talk should be included in the official doc.
Thanks John, this video really set the Record straight for me!
Hey man, this tutorial on Java Records is good! You broke it down so clearly, the basic parts makes sense. Thanks a lot for this awesome content!
Edit : Understood 50% of he video clearly and the rest 50% a little bit....revisiting Java...and Learning..
after i am learning about memory management, stack and heap and jvm internals i could really understanding this properly what a powerfull feature
So simple and clear explanation. I really appreciate your help.
Hi i am a french student , we started the poo this week , i think this vidéo gonna help me 😄
u have the best java keyword's tutorials, ty
Explanation is clean and clear. please publish more videos like this. Thanks
Explained quite clearly with detailed examples. Excellent tutorial! This is what I needed to start working with Records in Java.
Thank you John! You structure your videos exceptionally well and have a very clear explanation style
Thanks John!!! Always looking for ways to improve and writing clearer/better code.
Side Note…are you using Java 17 or 16? B/c “records” is not supported in Java 11.
I cannot believe I completed many courses and projects in Java without using this 😔🤯 My goodness, think of the time I could've saved! Thank you for making this video. It's so engaging, informative, and very easy to understand.
That means, that this stuff is not really important. It is not a unique cure to any problem you had.
he best person on TH-cam that explains java in such a great way
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
That's an awesome no BS explanation. Too good.
Hi John, Please upload Microservices and spring boot tutorials as well
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!
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.
great lesson as always , grettings from Morocco
Thank you, I've always wanted to learn about Records.
your videos really help me to focus on Java again :)
Thanks for the Video John! Greetings from Brazil 😉
Java is usually known for its cumbersome syntax but such awesome improvements like records would make java lovers more excited.
thanks, even i am russian, who doesn't know much english, appreciated your videos
Thanks a lot for doing this tutorial. Clear, easy to follow explanation as always.
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!
It's not as powerful as Lombok unfortunately
@@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.
@@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'.
@@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.
@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.
You are so underrated! Hope you reach 1 mil subs soon
Thanks for teaching me more about records, I was always teaching my fellow programmers about this in my workplace.
Very well explained, readable size text, excellent class! Thank you!
Your exposition is always so direct and simple. I love it 🙂
Hi dude, please do a series on java streams. This records are very crystal clear thanks
Love you, John. Best teacher.
Mindblown by this feature!
Hi John thank Q for ur valuable information sharing love from India 🇮🇳
You helped me understand concepts that was difficult to understand on my own.
This is really similar to records in C#. We don't have compact constructors though. I think compact constructors are really neat.
Your explanation is beautiful
Have been following your videos for a while now. Thank you for the awesome content 😊
Great presentation! Thanks!
@
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!
Hi John, you are the best!! please upload Microservices and spring boot tutorials :)
Thank you
Hello, John! Greetings from Ukraine! Wanted to say thank you for awesome lessons
Nice and precise explanation without any fuzz 🎉
That's a really good teaching... Thanks 🎉
Very well explained. Thank you kindly.
Tip: If you want to store mutable objects in records:
public record EmployeeRecord (java.util.concurrent.atomic.AtomicReference name, int employeeNumber) {} /* Here, _only the value of AtomicReference name_ (a String) is mutable; the value can be changed with employeeRecord.name().set("John"); and can be gotten with employeeRecord.name().get(); */
(or)
import java.util.concurrent.atomic.*;
public record EmployeeRecord (AtomicReference name, AtomicInteger employeeNumber) {} /* Here, _both_ the values stored by name and employeeNumber (String and _int_ respectively) are mutable. The value of employeeNumber can be changed by employeeRecord.employeeNumber().set(x); (x must be an int or an Integer (if it is an Integer, it will be unboxed)) and can be gotten with employeeRecord.employeeNumber().get(); */
/* FAQ: employeeRecord.employeeNumber().get() returns a variable of type int (may autobox to Integer). If employeeNumber is to be directly of type Integer, it should be declared as java.util.concurrent.atomic.AtomicReference employeeNumber . */
Keep doing it.
You know how to do, and Know how to teach!
Good tutorial. I will use this from now on, much more simple way to do the same thing. God bless you.
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
what is Lombok?
@@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) {
}
@@ThiagoHenriqueDS thanks, looks helpful!
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.
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.
my first video at this channel, let's check out the others one.
Ty for helping me to learn more about Java.
Thanks for this video
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!
you are best tutor in the world
Excellent video
Omg. You are so amazing at teaching. Thanks Master Yoda
Thank you so much , explaination was very nice.
Hey John. I am from Iraq, at first I would like to tell you about. Your way of explanation is wonderful, and I study programming as a specialist and understand you, but it is possible to ask me to do the Arabic translation feature because some of the sentences are somewhat difficult for him, I do not understand them correctly and I want to continue with you
Thank you 💗💗
Holy crap, how have I never heard of this? No Java TH-camr that I've came across has ever mentioned that records even exist. I've always thought they were similar to annotations, so I've never used them.
This removes so much redundant boilerplate from typical one use-data storage classes.
That's because they're a really new addition
Why haven't you just used @Value and @Data until now?
This video reminds me so much of the mCoding video on python Data classes!
❤❤
at the end of the video, as a bonus, if we were to create non-cononical constructors, they would have a strict rule that a constructor wouldn't normally have, which is that they have to call the cononical constructor in the end whether directly using one " this()" statement or multiple "this()" statements in case there were multiple non-cononical constructors.
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 :)
Thank you for explaining some unexplored topic
Well...wish I knew this a few years ago...I should really keep up to date with new features. Just reading an article once in a while might save me a lot of work. I love how the fields "getter" methods don't start with "get". I've always hated that (3 extra letters to type and doesn't fall in neatly alphabetically with the other methods).
First thing got in mind is use this for DTOs, but knowing inheritance is not allowed, I dont see use case for records. Getters/setters/constructors and others can be generated by your IDE, thus there's lombok ☺. Anyway thnks concise demo
Thanks I forgot about the compact constructor and now stripped 5 lines from my project
really cool!!!
Spring had some simplification,
but here it's much better and has also interesting options!
Thanks 👍👍
What do you mean by the Spring simplication?
Thanks a lot John! Would be there any video about sealed classes? It is also quite cool feature
Great explanation
This is like Case Class in Scala... Finally Java has it.
Perfectly explained.
This is great! I learned a lot from this video. But it left me wondering which versions of Java have records. Also, what about records that have many fields? Are records compatible with the builder pattern recommended for constructors with more than four or so parameters? Keep up the good work, John!
First question, answer is java 16
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
Hey John, Congrats on reaching 110K, please do videos on java streams, java sockets, Mockito and MVC in the future, thank you
That's similar to class declaration in Scala, except that there you can simply specify var or val in front of field name to make it either mutable or immutable. Or make it a case class with immutable fields by default. But in Scala, there is no need for that "compact constructor" because you can write any validation code directly inside the class body.
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"🙂)
Nice pace, and super clear, cheers my man
Awesome. Thanks.
I'd love to hear your take on lombok (since it still seems to be kind of controversial). I personally use lombok @data for this type of classes.
He has done a video about lombok: th-cam.com/video/ftKBLu47u_U/w-d-xo.html
I think @Value does more or less exactly the same as record.