Lambda Expressions in Java - Full Simple Tutorial
HTML-код
- Опубликовано: 6 фев 2022
- Full tutorial for Lamba expressions in Java.
Complete Java course: codingwithjohn.thinkific.com/...
Lambdas in Java can be very confusing and hard to understand for a beginner Java learner, but they don't have to be. Lambda expressions allow you to create a method implementation as an object, and you can learn how in this tutorial.
Lambdas were introduced in Java 8, and are one of the coolest things in the Java language. By the end of this video, you'll know all about how Lambdas work, and how and when you can use them.
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
One additional note - although lambdas do only work in the context of a functional interface, you don't necessarily need to always create your own in order to use one. There are many that are built into Java, and they cover most uses cases you'll see:
docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html
I swear John you must be going to my university with me or something this is the exact thing I needed thank you!
Thanks for this
Great, I was looking for this, thank you!
Good job , thank you for that !! Also I would love to see you making a video about streams and how we can associate the use of it with lambdas.
Regards 👍🏻
Please do Java Reflection, if there is a person who can do it well, it would be you
I am always impressed by how good you are at making yourself understandable, your explanations are all clear and meaningful. It's definitely a privilege being able to access such a high quality content for free.
Yes
Oh yeah!!!😀
The key point here like you say is lambdas allow method definitions to be used as variables/objects. Many other languages allow for function names to be passed as variables for callbacks and whatnot and Java never had a clean way to do that until lambdas. Only thing I would add to this is that putting the parameter type in the lambda expression is allowed and makes it easier to understand that the lambda is a method definition: (String p, String s) -> //code
thanks, bc i was wondering what was the point of all this, it didn't look like a step forward at first, it looked like a step backwards
It works like JS callback/anonymous function. The method definition: (String p, String s) -> {}; is indeed a caveat
Reflection allows that. And it exists since the very first versions of Java.
It even does more than that. It allows you to break scope limitations and call a private/protected/package method from places that are not supposed to see the method.
I used reflection once in my entire career. It was in java 1.2. And it was to access a method in a library that was erroneously declared as private by its author. At that time I didn't have access to a decompiler. Of course when I have a similar situation now, I simply decompile the class to create an override in my source code.
I wouldn't call that a clean way of doing it. You have to essentially create a type (functional interface) to which you then can dynamically assign an ad hoc implementation. In my mind, that's just a stupid way of doing it, compared to C or Javascript. What I would have done would be to introduce a parametrized type Function, that lets you create the declaration on the fly, like so: Function fancySquare = (String s, Number n) -> s + (n*n)
@@feynthefallencan't you just create that parameterized type yourself? The current implementation gives more flexibility.
Hi, John,
I'm not a quick learner, but I work hard.
English is not my native language, and I watch and rewatch your videos a couple of times - and I can say: if you keep doing this amazing videos, I might learn some java.
I'm reading a java handbook right now, but next, I'll take your course.
Head First Java book can be really helpful to you, it's really clear and easy to understand. It has translations to many languages too. You probably can find a PDF online. Use it as a complement to John's videos. Good luck!
You should start right now too
I've been doing Java based web application development for over 20 years. I often like to take refresher courses on things I've studied before. This is easily the best explanation with practical examples I've seen for Java Lambas. The concepts are clearly explained. Thanks John for making such a great video!
My biggest "a-ha" moment here was when you showed how we go from public void print() {} to just () -> {}. Super intuitive, very good work!
When I first started coding, I have used Java and these videos have been a great refresher on the smaller and intricate things that Java has to offer. Great videos! Already learned so many things.
I am currently studying computer sience and been literally devouring all of your videos, they have so much information, are easy to understand and have a good structure. Thank you.
Please don't ever stop uploading. These videos help me in my academics and coding in general a lot. Thank You.
This course is a gem, concise, clear and thorough, thank you!
I've been using lambda for a while but it's the first time I understand how it works behind the scenes, thanks a lot for this video!
First video I've watched of yours and I am beyond impressed! You explain things so perfect and clear which allowed me to understand it all so much easier! Definitely watching the rest of your vids! Amazing teacher!
I appreciate how your videos get straight to the point. I tried watching a video from another channel about a Java topic and at least half of the video could have been edited out with no loss of meaningful information.
Awesome. You succeed in summarizing the entire topic of the video in 30 seconds at the end, starting from 12:15.
I learned a lot. I've never looked behind the scenes of lambdas so far, but just accepted the shortcuts they provide.
I have no idea whether method references are worth tackling as well, but if they are, I'd very much enjoy a video on them.
I've been looking forward to a new video since your last video, and this one has been totally worth waiting for. Thanks so much!
I have been using lambdas for many years, first with Scala, then with Java, and watching your video, I am amazed how much I learned. Kudos to you for creating such as useful lesson...
I found Lambda Expression is the exact same Arrow Function in JavaScript. I think it's usable in terms of functional programming but don't know whether there is a need of it in object oriented language like Java!
Thumbs up for you, indeed you are a great teacher.
This was an excellent video! I have struggled to understand lambdas for a while and you just connected all the pieces that reading documentation and running examples cannot. Thank you!
I have been watching your videos for a while and I have to say you are an excellent resource. You explain in such an intuitive way. Now when I don't understand a concept, I check if you have done a video on it first. Thanks for all you do!
This is better then other courses you have to pay a premium for, your explanations are so evidently thought out in a clear to understand manner for the listener and that's absolutely beautiful. Thank you :)
You are a phenomenal instructor - you saved my behind in data structures and algorithms and this was a great refresher on lambdas.
I had to watch dozens of videos to understand lambda expressions. Finally i found the right one. Thanks a ton 🙏
Your videos are always so helpful for the Java beginner like me. Thanks John! Hope you always keep your good work.
Wow. This is the best explanation of lambdas I have come across. How you trim the expression in the beginning, removing access modifiers and so on is really great. Thank you!
That was extremely helpful in understanding what the heck is going on with the lambda syntax. I've seen them before but immediately understand it better after seeing him do that.
I have never seen anyone who can explain lambas expression as good as your. You help a lot for ppl who doesnt lambas.
Most wanted tutorial from you!!! Thanks :)
I discovered this channel today and already watched about 7 videos. Amazing! Thanks
This is a great explanation of Lambdas. Thank you, I have been a java dev for the last 9 years, I have never used functional interfaces or lambdas in a professional setting but I am getting ready for my OCA certification and this is an amazing explanation. This is the first time that someone has explained it in a way that made sense to me. I am most definitely going subbing to the channel.
Clear, concise and to the point. Nice video John.
Thanks a lot mate! I knew those things you were talking about. Just watched to see if you explain properly, and I can surely say that it was perfect. I will watch other tutorials you posted to learn even more.
Thanks John.
Clear and simple to follow as always 👍
You did in 5 minutes what my Uni prof. couldn't in two lectures. That goes to show how much people who actually use java professionally have a deeper understanding of java.
Oh yes, thank you so much for this video! I looked at many articles before etc. but couldn't really grip the entire thing or couldn't remember how to use them - now I can :)
Great video as always Mr John, lambdas been a pain in the ass for a junior developer like for long long time and I do gotta say that I'm addicted to your videos as I learned better than in my school
Your tutorials are great, they cut straight to the point and are very understandable. Keep up the good work 👍
i love your explanations! they are as clear as they get. great videos!
one of the best, succinct yet comprehensive overviews of lambdas in java that i've ever come across! thanks a lot
Java receives a lot of backlash from inexperienced and experienced developers of being too old school, bloated and lacking modern features and syntax, although.. ever since I have started watching your videos, I've seen a major improvement and they are really trying to keep things up to date as of lambda expressions which provide more of a functional approach towards problems.
Turns out you just need a teacher like John to really appreciate and understand it. :)
Also this feature has existed for a long time, version 8 where it was introduced came out in 2014. Since then they greatly accelerated their version bump speed, currently we are at version 17 with a lot of new features like local type-inferred vars, switch lambdas, data records and so on.
I am in my last semester as a cs major. You explain these concepts so well; maybe even better than my professors, and they are all really smart people!
This was a big help! I've been programming in Java for 5 years, but used it like a traditional language and didn't use lambdas. They were always a big mystery to me. When I took a Java skill test there were a lot of lambda questions so that hurt me. This short course explained a lot.
excellent explanation of Java. Thanks John for the amazing tutorials.
Wow, i've never understand lambdas that well, but rn, i am happy that i can make my code workflow easier, and shorter! thank you for your great tutorial
Hi John. Your videos are making me consider use java again in my projects
John hats off to your simplicity explanation. You have excellent command in your communication. 👏
This guy is on fire, every single video he posts is interesting and informative. I wonder how long he can keep this up!
Absoultly clear and concise! Thanks alot!
Thank you so much for the explanation! This is the best video on lambda topic that I ever seen. It is very clear and straightforward.
I love your videos, they are very well put together and easy for me to understand! Any chance you would be willing to make a intro video on Servlets?
I'v been searching all day... and finally a great explanation!
Thank you.
Clear, concise, to the point, thanks a lot !! Helped a lot
I find it amazing how I'm taking an advanced java course in college right now and these videos are literally covering topics we're going over. Just have to say you do an amazing job btw, literally learn more in these 12 minute videos then I do in 2 hour long lectures. THANK YOU!
OMG You are really really really a good teacher!!!
I had got stuck of understanding the concept of Lambda for days till watching this video!
Thanks a lot!!!
Waiting for this topic for a long time, and it has been delivered more than enough. Thanks John so much
+1, he's totally nailed it once again
Amazing explanation. When someone has the ability to explain such abstract example so smoothly that even the absolute begginer could understand it, that means that the person has huge knowledge about that matter. Thanx!
You are doing by far the best Explanations for Java and figuring out how to use all the Tools the Language gives you. Currently, struggling mighty with my Coding Exam in a couple of days, but you are saving my ass, so a Huge Thank You!
This is a great video, thank you for explaining lambdas in a clear and concise way.
I was looking through you channel like 2 days ago to see if you made a tutorial about since i have it in school right now and 2 days later u upload it. THANK YOU :D
Your videos are great, well thoughtout and explained various cases, video is not super long. Code is big on screen which I like and the quality overallis solid. Thank you for the effort of putting up these videos. Also, saying why is it useful on the other vids as well makes it so easy to understand why it even exist and why you should use it. Good job.
Hi John,
Thanks a lot for your commitment,
by watching your videos every day I learned so much about Java.
one of the best way thad happened to me during my Java learning journey
was finding your channel. 😃😃
With more than 20 years experience in Java programming, you really explain advanced topics so simple!!
Listen bro, this is the best explanation of Lambda's I've seen on RUclips. Great job. I just subscribed.
John ! I want you to know that you're the coolest Java teacher. I injoyed your courses a lot , so THANK YOU !!
You say it so simply that I don't understand why I didn't understand it before watching this! Thanks!
That is the best explanation that I have seem so far.
Thank you!
It really feels good when understanding more about how it work when I literally use it everyday especially in java stream. The Best Explaination I can find in YT. Thanks alot
Thanks John ... very easy to understand your explanations! Cheers
Never came across a more clearer explanation!
Been a while i have done OOPS. Doing more of cloud coding in azure where we are using lambda expressions. Came back to check this out and i feel like goimg back to developer role. Thanks so much. You really made it as simple as you could
Thanks to your video, i could understand bascis of lambda. I could catch every info you provided, but couldn't understand from other sources.
Thank you so much !
Amazing job and clean, step by step you complete the course! amazing
one of the best videos on Lamda
Short and to the point
Thanks @CodingWithJohn
Amazing video. Clear and precise. Thanks for that
Very clean explanation !! Thanks @Coding With John.
Thank You. Your videos are really helpful for improving the skills
Great video, easy to understand Java tutorial, not a simple thing to find. You earned my subscription.
Awesome tutorial! Love that it was made simple.
very well explained, especially the last part is interesting about the functional interface, reminding only one abstract method.
Never have seen a so clearly explanation about java lambdas. You rock!
Once again, a great video, very understandable! Thank you!!!
Hey John! Awesome video! I have one practical question about it - how can you ensure that a program with lambdas will stay readable and maintainable enough? It seems much harder to read and in some cases have multiple points where it can fail.
The most 'simplistic' explanation of lambda i've ever seeen !!! 👍👍👍
Such a great and clear explanation. This might solve a problem I've been trying to solve in a personal project I'm building! There are still some complexities in my code that make it not exactly straightforward, but I think it's a really great start! Without this, I currently have five distinct methods that are near repeats of themselves except for just a couple of lines of code! I'll try it out and see if it can make my code a little less repetitive! Great video, great channel!
Really nice. I am def enjoying going through your postings! Taking Notes!
This tutorial was concise and precise, thank you for such a clear explanation!!!
This simple and best video to understand lambda. Good one John.
Awesome, looking forward for more such videos.
Thanks, man it's very helpful explanation of this topic. I needed help with return type lambda implementation.
Lambda is a shortcut to define an implementation of a functional interface. Instead of creating a class that implements that functional interface and adding an implementation that you want of that single abstract method, and create an object of this class, you simply create a lambda expression that contains the implementation of that functional interface method that you want. Man this summary clears out all my confusion about the significance of functional interface and lambda expression. Thank you soooo much for the clarification!!!
Thanks for your work, John! Well done!
Hey Jhon,
A humble request, can you please go in depth and explain the difference between Abstract Class and Interfaces.
Which one to you use when, and why to even use 1 at the first place.
Also, after the introduction of default,static and private also I guess.
What exactly is the difference now.
Basically an abstact class is...well, a class, in this case, one that is designed to be inherited, you put the basic atributes, and then each subclass does extra stuff and maybe change's some basic atribute
For example, Dog, ,whale,goat, Bat, Human and bear are all mammals, they all have hot blood, have some form of fur, and females feed their offspring milk, but the dog barks, the whaleives in the water, the goat climbs steep surfaces, the bear hibernates, the bat has a sonic radar and the human stands on two legs
Meanwhile an interface can be considered either an addon or an common atribute between things that are not related or achieved in completely different ways
For example, a bat, a hummingbird, a dragonfly a plane, hellicopter and a rocket all can fly, but do so in completely diferent ways, a bat's wings are just mutated giant hands that they still use grab things or themselves to surfaces, the hummingbirds have speciallized wings that allow tgem fine control of their angle and speed so they can hover, dragonflies have their four wings as extra appendages instead of being their "arms" , hellicoptets push air vertically to lift their weight while planes push it horizontally to gain speed and they win height by shanging the air pressure between the higher and lower parts with the dessign of the wings, an finally a rocket is basically a controlled explossion
Mechanically speaking, the biggest differences between interfaces with default methods and abstract classes is that abstract classes can declare visibility other than public (e.g. protected abstract methods are a common pattern), and they can have state (variables) of their own.
For example, AbstractCollection could be turned into an interface with default methods just fine. As it only has methods, no state (and frankly I'm a bit disappointed they didn't just fold it into the Collection interface).
However, AbstractList could _not_ be. As it has a protected method (removeRange) and internal state (the number of modification tracking thing)
You explained so well, to this time I was not able to understand anything related to lambdas and functional interfaces, but your video opened my eyes! new Subscriber and will check all of your courses right now!
I must say you are one of the greatest coding teachers I have ever seen! Thanks John!
my first time is watching your videos, and you got me to subscribe right away because of how good you are. Great explanation
Ty for the many tutorial it really help me so much
Great video explained concisely thanks for the time John you the best
Hey dude, you're the best. you can explain hardest concepts just like a piece of cake.
Hi! I love your videos and I'm learning very much with you, please do a tutorial about Streams in Java!
Great video, I really like the summary at the end :)
Amazing Video, That was Smooth and clear Thanks a lot
After watching so many videos, its first time I'm feeling that it's the best explanation 👍
Love your videos, would really like to see some videos on design patterns