Generics In Java - Full Simple Tutorial
Full tutorial for using Generics in Java!
☕ Complete Java course:
codingwithjohn.thinkific.com/...
Generics in Java can be very confusing for beginner Java learners. Generics are one of the coolest features in Java, but the syntax may not make a lot of sense at first.
In this beginner's Java tutorial video, we'll talk about why generics exist, why they are useful, and all the ways you can use generics in your own Java programs.
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
Пікірлер: 1 100
I’ve “known” Generics for many years now but never really understood the difference between usage of wildcard vs a type parameter, even after having read the official docs a gazillion times. But your just one 15-min video has made everything crystal clear. Amazing! Thank You for making the video :)
@kakasy5335
2 жыл бұрын
as for me, the best explanation was in Bruce Eckel's book "Thinking in Java", everything fell into place after reading this monumental book
@caiocesarmelolopes2156
2 жыл бұрын
yeah, I like to watch these videos, always has something we don`t know :p
@adipurnomo5683
2 жыл бұрын
Same here
@sssxxxttt
2 жыл бұрын
Thanks, for this comment made me rewatch the end. Lost focus earlier :)
@jaimesastre6393
2 жыл бұрын
Great explanation. I just have a stupid question for Cat. If you ask to shout(new Cat()) , a class, how is it that it prints 'meaw'? I didn't see clearly the class.
This is the greatest Java tutorial I have ever found on KZread. Not too lengthy, covered huge concepts within a few minutes. As well as clear and understandable English. Thanks.
@YtubeUserr
4 ай бұрын
What are "huge concepts"?
My attention span was 5 to 8 minutes before watching this video, now it's 17 minutes. Thanks Jhon!!
I just began my Education in Software Developing, one year passed and I've learned so much more from like 5 Videos from John than I've learned in the entire year, that's insane.
Hands down, the best explanation I've ever seen. What a teacher.
This tutorial was so simple that I immediately implemented the generics very easily to one of the projects that I'm working on whereas a day ago I was just refraining from doing it just because of not being very confident with the Generics concept. Great stuff John, this was a very informative yet very simple to understand tutorial. Keep up the excellent work.
OMG i never knew i can learn these many things in 17 mins. Man i would love to work under tech leads like you. People like these improve quality of life as well
What I think it's missing is the generics that use the super word, like List, and explain the difference and the use cases of extends and super.
@sameerkadgaye2048
9 ай бұрын
Yes pls explain wildcard with super keyboard
@TrisnoadiWikantoro
5 ай бұрын
@@sameerkadgaye2048slammed my keyword
Another well-done tutorial here! Can't wait to see one on java 8 streams as I have not really found one that goes deep into these concepts.
Among tons of courses I have ever seen and learned, I found out that Coding with John is the best. He explains confusing things in such an easy way. Additionally, his voice is so clear and easy to understand, that I can focus only on the code running on the screen, whereas I need to pay attention to reading cc in other courses. You're amazing, John!
Honestly, this video clearly explains what generics is all about. It took me awhile to understand it but right here, it just takes 17mins of your time. Thanks for putting out great and concise content on Java!
I’ve never known anyone to explain things as easily as you do, fantastic video as always.
I'm Brazilian, I learned more in your class with you speaking in English than I normally learn in the classes I attend in Portuguese. Very good teaching. Thank you so much!
There are just straight up some of the most perfect tutorials for someone like me, even 6 years in the Java industry and now upgrading to newer versions. Thanks John!
I went through a 3 hour lecture on OOPs and after that went through a couple of KZread videos but I was not able to fully understand what exactly generics were and why are they used. Then I came across this 17 minute video which cleared all my doubts and made everything super super simple. The difference a teacher makes is unbelievable. Subscribing and watching other videos too. Thank you so much!
This is by far the best video on generics in the entire universe. Mad respect for this dude 🙏🙏
This is my first comment in KZread after many years , video had so much good content and value, Please Post more videos on generics in real time application , as production ready code that we use for configuring external dependencies Congrats John , Keep up the Good work ❣️
You have quickly become my favorite Java tutorial KZreadr! Thank you for demystifying confusing Java concepts! :)
The way you explain with coding examples showing how they work.. that too in a simple way is amazing.
I was looking for a short playlist/tutorial to understand the generics concept it was a bit confusing for me as you said. But this.. just one video cleared the concept. Thanks a lot! Keep making such videos👍🏻
Beautiful Tutorial. It’s just amazing how you were able to explain this complex topic very easily. Keep it up John you are adding value to lives. God bless you for the good work you are doing sharing knowledge
Great content, John. Terrific how clear you are when explaining.
Your videos are clutch. Your a life saver. My professor makes up a whole bunch of super complex examples when attempting to explain these topics to the class but just ends up confusing us due to the complexity of what his code is trying to do.
This is no longer super confusing, best tutorial I've seen on the subject, thank you John!
*Hey John, can you please make a video on lambda expressions in Java? Would really appreciate!*
@akshaylonkar713
2 жыл бұрын
Waiting for Lambda, Functional Interface, Streams
@richardday3136
2 жыл бұрын
@@akshaylonkar713 l -> ( kzread.info/dash/bejne/lmeT2M-de7arY8Y.html )
@jaykay7932
2 жыл бұрын
lambda is straight forward. the main function provides the data and you perform the operation within the parenthesis ie someMethod(x -> x.result ? 1 : 0)
@pinolskun8764
2 жыл бұрын
@@jaykay7932 Your terrible attempt at an explanation gone wrong is precisely why these videos are instead highly appreciated. Leave the explaining tho who knows how to do it
@Hughsie28
2 жыл бұрын
I don't think I can keep up at Johns level as Pinols says, I'm also beginner/struggling with lambdas a bit, but from what I have learnt is anything after the "->" or in the "{ }" after the arrow is like the contents of a function method, any variable before the "->" is the current item you are iterating through. (It kind of reminds me of Java callbacks in a way) hope this example syntax below might be useful, I'll use streams as an example it seems a great way to use lambdas // Without curly braces (1 liners) List numbers = new ArrayList(1,2,3); numbers.stream().forEach(number -> System.out::println); // With curly braces (multi-liners) List names = new ArrayList("Dave", "John", "Andrew"); names.stream().map(name -> { if (name.equals("Andrew")) { return true; } return false; }).collect(Collectors.toList());
The most understandable and humorous java tutorials, I hope there will be tutorials or explanation for Spring or javaFx
Hey man, I just want to say thank you. I've been struggling with this topic for a while now and now I feel a lot more comfortable working with generics after watching this video. You're the best!
I literally love tutors who not only explain the way to write a code but also follow the technique of clearifying why we use this instead of that which is incredibly useful . Thanks a lot ❤❤
I never understand the right way of generics, I always have a kind of confusion about that, so here comes a 15-min video that clear everything. Just an amazing work! Thank you for make this video!
I can't remember, too long ago, who recommended it to me, but I learned a lot from the, now dated, book "Just Java 2" by Peter van Der Linden. Your presentations are really extending and refreshing my knowledge in a very pleasant and easy to access way. Makes me want to code more.
I have been using Java for more than 10 years now and have to admit that I hadn't understood generics so elegantly before. Thanks a lot for the video.
thank you so much john, i've studied Java a few years ago but not in depth and i totaly forgot about generics. you made it so simple yet clear
I know generics for a while. I remember my professor explaining about it and he spent kinda 9 hours, in 3 hours classes to explain what you have done in 15 minutes, unbelievable!!! Shout out to you!!! 👏🏼👏🏼👏🏼👏🏼👏🏼
Sensational lecture! Dude, please become a computer science professor! Your lectures are the best! Thank you so much.
Thanks for clarifying the usage of each. I was mostly confused about ?, but it now makes sense that its used with collections rather than individual objects.
Honestly I have learn many things about generics in this small video. Thank you John for such a nice explanation and hands on demo on generics.
Hey John, thank for the tut! You made generics so simple to understand. Would love to see tuts on followings; Method referencing, Lambda Functions Optionals Stream API Thanks again.
@flexprods
2 жыл бұрын
Totally, Lambda is really confusing
@TheShlips
2 жыл бұрын
@@flexprods no it isnt
@Shivam8Pandey
Жыл бұрын
That's the most simplest part of java 8 😃
Outside generics, a solution for IntegerPrinter class, we could change the field and constructor parameter to be of type Number to accept both Integers and Doubles. As for strings, we could just change the field to an Object to just have a common supertype, as nothing is later accessing the actual value anymore. Don't get me wrong, I liked the explanation. But often when showing out examples to show the initial problem, my students would point out another solution (in this case Inheritance/substitution principle), which might make the other solution look (generics) needlessly complicated. Especially in this case, the println -method and the class itself are just consumers, they don't care about the actual object type. The field does, yes, but println just consumes an Object. I think a better example right here at the beginning would be to have a simple getter as well, to demonstrate the actual need for generics. Thanks for the video though, I'm just looking for more examples and alternate explanations as I'll once again teach basics of object oriented programming this spring semester.
This is by far the best short tutorial on generics seen so far
I swear, without you and your videos I would not be passing my Advanced Java class this semester. Thank you so much!!!
Great Video, but I'm confused on one thing, at 15:11 when you created the printList method , the Arguement was List myList and you said this is a list that will hold any type of object, but if you wanted the list to hold any type of object why didn't you just write List myList? Isn't that why one would use generics for like you explained in the video?
Wait...what Johnny Sins is also a Software Developer ??😂😂
@Mwzik
6 ай бұрын
😂😂
@Its_mee_____
3 ай бұрын
If your father is bald will you also call him johny sins😂😂😂
@leomagsun9533
Ай бұрын
Sorry to say after watching his file handling video i thought he's similar to Jhonny sins and here you go I got a comment 😂
Thank you so much for making your videos. I have problems with concentration of attention and memory, and it is difficult for me to listen, watch and read something for more than an hour. I am now in my first year at university and your videos help me so much to understand the material better and remember it for a long time.
Love the explanations when you show the problem that this concept solves. It makes it more clear to understand !!
I am a junior Java back end developer, your tutorial is so efficient to explain everything clearly, thanks a lot . Recently, I review your video contents in spare time again and again.
Within only 17 minutes you helped me a lot for my upcoming exam! Thank you John! I will def check out your other Java Tutorials :)
I wish I could like this video a million times! I can't express how much your explaination helped me understand generics! Great video John. Thank you!
Great explanation @John. Made things easier to me. Even after going through multiple video/pages on generics ,I was still not clear and confident about generics until I saw this video. Thanks!
This man is just awesome.....I wish I have a teacher like this person in my previous semester ... And I got to know him now finally god hears my prayers... don't stop these tutorials man.....these are life for people like us
One of the best tutorials on Generics you'll ever see. Great delivery.
I can't thank you enough for such a superb lecture. The first 10 minutes already helped me grasp the concept pretty well.
Fantastic video. The "why" in the beginning is what really solidified my understanding as to why we need generics. I know how to use generics, but now I understand why we really need them! Thank you!
I've been a SDE for a couple years and found myself using generics forever without actually knowing what was going on. Thanks for the background and clear explanation!!
Your didatics, examples and video structure is fantastic. You managed to explain things in a very understandable way, while some professors take many classes to say it poorly. Keep it up because it surely is helping many students! Thanks a lot!
Clear as a piece of crystal. Explanations are so well-planned and friendly to new Java learner. Thumbs up to you John!!!
Honestly, this video clearly explains what generics is all about. It took me a while to understand it but right here, it just takes 17mins of your time. Thanks for putting out great and concise content on Java!!!
Hi John, this is such a good refresher on Generics .. Love the way you explain making it super simple to understand
This is the actually the best explanation o generic types ever, not only for Java but the concept as a whole!
Glad I've found your channel, your way of explanations and the form of presentation fits my attention span and comprehension better than some other tutorials around. Subbed, thanks!
This might be the best explanation ever. Every video I have watched of you is totally amazing. The flow you get from one idea to the next is next level. Thank you
This was one concept in Java that I kind of knew but didn't fully understand until today. Thank you very much for this video!
Thank you for this tutorial. I like all the pauses you put here and there to emphasize some important concepts. I completely echo all the positive responses previously posted here. Thanks.
Happy! Today I am so much happy to find this video, it's the first video that i just watched on generics but now i am going to follow up his channel. The excellent way of teaching, to the point, best explanation with best examples. Thank you so much John for making programming concepts so much easy.
OMG John....really appreciate your videos! I am currently working with Java Spring, even though I go through the whole book Thinking In Java. Still got some questions that I don't understand. Your videos do help me a lot to rethink and solve all the questions!
The explanation was quite exceptional. i am a java engineer for 5 years and now only i got to know the full context of the generics.. thanks and keep feeding..
This was such a good video and the explanation was so smooth. Thank you for this amazing video John!
Short, well explained and on point. You sir, have my thanks!
Lovely, lovely work John. Generics are a bit of an odd beast for many developers, but I feel like this video is one of the better examples for generics, wrapped up in beautiful little tutorial
I literally love you. You made my exam preparation 10 times easier. Keep up with the good work! I love your videos and courses. Simply amazing.
I did mountains of Java from mid-90's to 2010-ish, then focused on an architect role. I recently had to understand a new Java framework and it uses all these new Java features - I was having a hard time scanning through the code. THANK YOU for the clear and concise explanation.
Great video, I never really understood the conventions of other's code leveraging generics until you put it so simply
You make me crave for learning more and more. Amazing work! Please keep making more videos and they should be long
Awesome video! Explained some of my questions towards generics very clearly and in a straightforward fashion.
John, you are doing a great job. The explanations were very clear and easy to understand. Could you please create some videos on Java modularity
hi C# dev here. I learned way more in this course for java then any course for C#(since syntax is really similar). Its brilliant keep it up!
This is wonderful. I am begining to appreciate the power of Generics in Java. Thank you for this brilliant piece.
For the first time, I can understand every concept about generics in Java. Thanks man!
You are the single best lecturer I saw for java for recaping. Good job man
Thank you John ! Clearly understood what Generics is and how it works. All your other tutorials are also awesome.
Brilliant. You clearly have a talent, John. Please continue with what you are seemingly very good at. 😎👍
Brilliant video! I love the way you explain complicated stuff in Java in a brief, concise but yet interesting manner. Many thanks!
That is so amazing, I think I finally got what generics are about, thank you!
I wish my intermediate Java programming class was just your videos imbedded with the labs and questions I would fly through it. Thank you
It's really delightful to hear you explaining things. Thank you.
This is one of the best explained Java concepts in KZread. Thank you so much :)))
Man, you changed my life with this video, i was having a lot of problems trying to unsdertand how(the first thing of my subject works) generics works and I hasn't found anywhere in my mother tongue, i was thinking that i wouldn't be able to understand how does that work until I found you! The explanation made me think by other perspective and made me confourtable to understand how does all of this works( even missing somethings like what does have on animal or how does exactly the try catch trow and trhows works) and now i'm ready to understand a lot more thigs of my classes. THANK YOU!!!!! SO MUCH!!!!!!!!! You are crazy man!
This could possibly be the best explanatory video I have ever seen. Thank you.
Now THAT cleared things up quickly. Thank you John!
This is hands down one of the best Java channels and video tutorials I have seen available on KZread! Earned a sub!
Awesome video as always! Would you do a second part showing the super key word and the difference between variance and contravariance and also where would one want to use the latter?
Thank You So Much.... Finally Even After 2 Years Of Professional Experience Got To Know Generics Clearly.... Thanks A Lot....
thank you so much teacher. I have never understood generics in practice as a said you even I known what is theoretical. Again many many thankful for you
You have gotten me through my CS classes thank you so much, would you be able to do a video on collections?
Best explanation ever for java generics. You have my lifetime respect
it s my first visiting to your channel , using generics was something beyond my understanding aka nightmare , now i get this concept right . thank you sir ... very exited to watch your next videos
Great crash course on Java generics. Each time during the video I was like "What about this situation", you covered it shortly after, which was great. Thanks.
Today I got the actual use of generics, ty so much John 😀 I subscribed your channel, So from now I will follow your tutorial.
This has made everything very clear very quickly. Thank you so much!
Oh my gosh you for making this video and explaining the way you did. I have been having trouble wrapping my head around this concept.
I just found your channel, John. I’m still new to Java (