Lambda Expressions in Java - Full Simple Tutorial

  Рет қаралды 746,620

Coding with John

Coding with John

Күн бұрын

Full tutorial for Lamba expressions in Java.
Complete Java course: codingwithjohn...
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.audibletria...
🖥️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...
☕Complete Java course:
codingwithjohn...
codingwithjohn...

Пікірлер: 614
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
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
@rokitap.w1193
@rokitap.w1193 2 жыл бұрын
I swear John you must be going to my university with me or something this is the exact thing I needed thank you!
@libertymedicalcommunicatio4908
@libertymedicalcommunicatio4908 2 жыл бұрын
Thanks for this
@Hufsa
@Hufsa 2 жыл бұрын
Great, I was looking for this, thank you!
@yasseromari1074
@yasseromari1074 2 жыл бұрын
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 👍🏻
@babythedude
@babythedude 2 жыл бұрын
Please do Java Reflection, if there is a person who can do it well, it would be you
@felipe2637
@felipe2637 2 жыл бұрын
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.
@gatescob
@gatescob Жыл бұрын
Yes
@ntigirishari
@ntigirishari Жыл бұрын
Oh yeah!!!😀
@danielcommins1285
@danielcommins1285 2 жыл бұрын
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
@stepbystepcoding4113
@stepbystepcoding4113 2 жыл бұрын
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
@enfieldli9296
@enfieldli9296 Жыл бұрын
It works like JS callback/anonymous function. The method definition: (String p, String s) -> {}; is indeed a caveat
@christianbarnay2499
@christianbarnay2499 7 ай бұрын
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.
@feynthefallen
@feynthefallen 7 ай бұрын
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)
@danielcommins1285
@danielcommins1285 6 ай бұрын
​@@feynthefallencan't you just create that parameterized type yourself? The current implementation gives more flexibility.
@aardappel3693
@aardappel3693 2 жыл бұрын
Normally I love your explanations. But today I got very confused.
@forreal_bhenchod
@forreal_bhenchod 3 ай бұрын
@@chrisstucker1813 thanks
@gingersoda2524
@gingersoda2524 3 ай бұрын
Me too
@KhaledAhmed-cs8rv
@KhaledAhmed-cs8rv 3 ай бұрын
His naming of the functions was way off. Print printable print thing.....
@bullshitul
@bullshitul 3 ай бұрын
The thing with the printable thing is that you should only try to print something, a thing - object, that has a print method. Thus a printable thing. Printable is the class Thing is the object
@djk1288
@djk1288 Жыл бұрын
My biggest "a-ha" moment here was when you showed how we go from public void print() {} to just () -> {}. Super intuitive, very good work!
@timsnyder1000
@timsnyder1000 2 жыл бұрын
I'm trying to understand lambdas and getting increasingly frustrated with the topic. I get the "how" to use lambdas (mostly*). This video explained how to code a lambda. But what I fail to understand is "why" use lambdas. To me, lambdas make code more verbose, more cryptic, and harder to read. I'm not getting the purpose or value of them. I'm assuming there is some useful purpose, I just don't see what it is. Is there a practical example of where a lambda would contribute positively to the readability or capability of the code? As for what I mean by "mostly*" (above): I keep hearing that lambdas create a portable piece of code that can be passed around as a parameter, presumably to be used elsewhere. But I never see it being done. The examples I've seen, including this video, show the lambda code being used in-place, once. Where are the examples of it being passed around as a parameter? If this is the point of a lambda, where are actual examples of that?
@cherryandjaji5694
@cherryandjaji5694 3 ай бұрын
most common problem occurs when we have 2 interfaces with same abstract method name and signature and our class implements both of them and that moment compiler is confused to which one it has to override since both the methods are same from two different interfaces . At this situation lambdas are handy where you dont really need to implement the interface , you can create a reference to your interface and implement your abstract method logic directly .
@andersonabe5044
@andersonabe5044 2 жыл бұрын
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.
@fabiorachid3430
@fabiorachid3430 2 жыл бұрын
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!
@emmanuelnsiah8036
@emmanuelnsiah8036 11 ай бұрын
You should start right now too
@carlellis9647
@carlellis9647 2 жыл бұрын
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!
@redy55
@redy55 2 жыл бұрын
Whats the point if lambdas though except saving you few lines of code and making it less readable (sometimes) in the process? Can you do something with them you couldnt do otherwise almost as easily?
@raz0229
@raz0229 2 жыл бұрын
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. :)
@Quinteger
@Quinteger 2 жыл бұрын
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.
@self-learner4934
@self-learner4934 Жыл бұрын
Hello, fellow JavaScript developers! Don't panic, it's just an arrow function.
@castletown999
@castletown999 Жыл бұрын
Maybe it's just me but I have a problem with tutorials like these: they jump into how to use a feature without explaining why it exists. I have programmed in Java a long time ago, before lambdas, but after watching this tutorial I am still unclear as to what problem they solve. Accordingly, I don't know when I would use it. The "why" has to be inferred from the "how". Thanks for listening.
@robertzaryal3416
@robertzaryal3416 2 жыл бұрын
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.
@actualprogramming
@actualprogramming 2 жыл бұрын
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.
@dumpsockpuppet5619
@dumpsockpuppet5619 2 жыл бұрын
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
@TechSY730
@TechSY730 2 жыл бұрын
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)
@mythilikalidasan
@mythilikalidasan 2 жыл бұрын
Most wanted tutorial from you!!! Thanks :)
@southern_smacker
@southern_smacker Жыл бұрын
Wait. If I have 3 different interfaces, for example Cow, Cat, Dog. Each defines its own single abstract method “void makeVoice();” And then I want to use a lambda expression of makeVoice() function, then how compiler will decide which interface out of the three I have implemented, as I am not using “implements Cat” or “implements Dog” and so on. Please clarify this confusion. Thanks 🙏
@zr60
@zr60 2 жыл бұрын
Why would you need lambda expression for this? can't you just print it directly? Can you use lambda expressions without a functional interface?
@delphi8333
@delphi8333 2 жыл бұрын
I have only ever seen lambdas used to do real simple things like printing something or doing some math, would you be able to show us some other examples that are more advanced to do something more complicated please please?
@frantisekfilip1888
@frantisekfilip1888 28 күн бұрын
Not using return might be shorter, but it's definitely not more readable. Personally, I would rather get rid of lambdas entirely. I don't mind writing those few extra lines of code.
@yavgel
@yavgel 3 ай бұрын
Could you please explain in the new video about:: method reference operator? Thank you!
@imakhlaqXD
@imakhlaqXD Жыл бұрын
Java devs : Lamdas are so difficult. Javascript devs : wtf this is arrow function. We are dealing with it from day one.
@antalbojtos4413
@antalbojtos4413 2 жыл бұрын
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.
@xsraut
@xsraut 2 жыл бұрын
Please don't ever stop uploading. These videos help me in my academics and coding in general a lot. Thank You.
@rohitkharche7562
@rohitkharche7562 2 жыл бұрын
Now this makes perfect background for "Streams", please make a video on that also. 🙂
@tsepolesibe2115
@tsepolesibe2115 2 жыл бұрын
Hi John, can you kindly consider doing a reverse linkeklist video in the future please. thanks in-advance.
@kancharlasrimannarayana7068
@kancharlasrimannarayana7068 Жыл бұрын
if it have more interfaces out their, then how compiler will find out which this lambda expression belongs to?
@johnmisley5411
@johnmisley5411 2 жыл бұрын
Awesome video! Do you think you could go over trees next?
@jaswdrTheDev
@jaswdrTheDev 3 ай бұрын
I think lambdas hurt legibility in Java, it is harder to understand what the code is doing
@LthiagoR
@LthiagoR 2 жыл бұрын
Thank you! Now proceed with Streams in java, pleaaaseeee
@JonasKeil
@JonasKeil 2 жыл бұрын
Great Tutorial, sir!😁🎉
@phonesj3422
@phonesj3422 2 жыл бұрын
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!!!
@mohammedamr5650
@mohammedamr5650 2 жыл бұрын
I think the idea of passing in lambda as an interface is something that Java needs to regret about for a long time. It is undermining the idea of the interface. It should have come up with more intuitive approach like in C# (Action and Func)
@MiguelFarah
@MiguelFarah 2 жыл бұрын
Excellent video, as usual. With that said, I find the chosen syntax for lambdas in Java to be quite less than ideal (Scheme, which I used a lot back in the day, was a lot more clear in this regard), but... any discussion about it will inevitably end up in the taboo subject of adding reserved words.
@colbyboucher6391
@colbyboucher6391 2 жыл бұрын
I imagine part of new reserved words being taboo is because Java's already so huge? It seems like Java's at a point right now where it's almost trying to catch up to other JVM languages, but all the "old stuff" gets in the way. It's becoming like a museum of the history of "programming culture" from C++ to now.
@uhlan30
@uhlan30 2 жыл бұрын
Great video! The one thing I wish you had touched on is the double colon operator, especially creating an object with ::new. I’ve seen people call this a lambda expression but I never understood how it works, and every time I see it it just looks like magic. Maybe a topic for a future follow-up video?
@Quinteger
@Quinteger 2 жыл бұрын
I can try to answer this one for you. This is what's called method reference - instead of implementing a lambda from scratch you instead pass an already existing method which has the exact same arguments and a return type. For example, instead of implementing a lambda that adds two double numbers "(a, b) -> a+b", you can just pass "Double::sum" which is an existing static method in the Double class which does exactly that.
@faraskhan3940
@faraskhan3940 2 жыл бұрын
John my experience has shown very fast processing compared to standard expressions. I found Lambdas to behave more like C then Java . Am I just hallucinating or is this really happening?
@zipkitty
@zipkitty Жыл бұрын
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.
@aidoka2000
@aidoka2000 2 жыл бұрын
excellent explanation of Java. Thanks John for the amazing tutorials.
@jalilhasanli5577
@jalilhasanli5577 2 жыл бұрын
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.
@codewithvicky
@codewithvicky 10 ай бұрын
What I have understood that Java has complex flow to passing functions as arguments. POV: Swift or Javascript Developer
@kvelez
@kvelez 10 ай бұрын
public class Lambdas{ public static void main(String[] args) { IPrintable lambdaPrint = () -> System.out.println("Meow."); printThings(lambdaPrint); } static void printThings(IPrintable thing){ thing.Print(); } } public interface IPrintable { void Print(); }
@caniggiasyabil470
@caniggiasyabil470 2 ай бұрын
does anyone know why he put Printable as the type there: Printable lambdaPrintable = () -> System.out.println("Meow") shouldn't it be 'void lambdaPrintable = () -> System.out.println("Meow")' or something like that?
@TerminallyUnique95
@TerminallyUnique95 2 жыл бұрын
What if I have a Lambda like this private String[] getFolderNames(String basePath) { URL resource = SpriteLibrary.class.getResource(basePath); File file = new File(resource.getFile()); return file.list((current, name) -> new File(current, name).isDirectory()); } I am get null pointer not for file, but for the return? Any solutions?
@GuilhermePalazzoRodrigues
@GuilhermePalazzoRodrigues 2 жыл бұрын
This course is a gem, concise, clear and thorough, thank you!
@ivankobyuk8385
@ivankobyuk8385 2 жыл бұрын
Huge THANK YOU from Ukrainian developer! / Велике дякую Вам від українського розробника!
@Arnott_me
@Arnott_me Жыл бұрын
finally understand this thing...
@twisterwiper
@twisterwiper 2 жыл бұрын
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!
@burgerbob7324
@burgerbob7324 Жыл бұрын
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.
@tiger7858
@tiger7858 2 жыл бұрын
Thank u sir , it really helped me a lot.
@horimberebertrand3220
@horimberebertrand3220 3 ай бұрын
Thank you very much for sharing this video. Could you please make a video explaining the link between LAMBDAS and METHOD REFERENCE in Java 8 ?
@EldawodyBlogspot
@EldawodyBlogspot 2 жыл бұрын
thank you amazing tutorials. very clear and to the point can you make a video about predicates?
@darkestccino5405
@darkestccino5405 2 жыл бұрын
Why would I want to write: printThing(() -> System.out.println("Meow")); when I could just write: System.our.println("Meow")); ? If lambdas are giving coding to another method to be executed, why not just execute that coding normally? Passing that coding to somewhere else just seems the be an unnecessary step.
@mattongbp
@mattongbp 2 жыл бұрын
While interface Printable CAN be implemented in CAT class, it is BAD OO design and usage of Java Syntax. You should name Printable as Noisy and method as makeNoise. You are using Java like C++(BAD OOP Language).
@jilliansechrest5906
@jilliansechrest5906 2 жыл бұрын
You are a phenomenal instructor - you saved my behind in data structures and algorithms and this was a great refresher on lambdas.
@robertoj.9509
@robertoj.9509 2 жыл бұрын
Who, and why, created this complicated technology?????!!! Jesus... I didn't understand anything.
@TheRealAnkitSharma
@TheRealAnkitSharma Жыл бұрын
Hi john, It's a great video on the lambdas. I followed your steps to practise but " Printable2 lambdaPrinter = (s) -> "Meowzaaa " + s; pokerThing(lambdaPrinter); " is not printing anything. Can you tell or give a hint . No error were also there it compile fully but don't print any thing. Time Stamp 9:25.
@vicke909
@vicke909 2 жыл бұрын
Can you do a tutorial about Streams aswell? And maybe combine lambdas and streams? Would be much appreciated, love your videos!
@alfredomenezes8814
@alfredomenezes8814 2 жыл бұрын
Would be great!
@afrasm2478
@afrasm2478 Жыл бұрын
Took this 13 minute video over my 2 hour lecture and i can proudly say i understand it better and didnt ever fell asleep in btw
@almogpatash1234
@almogpatash1234 2 жыл бұрын
public class CodingWithJohn implements understandable.... haha.. thank you!
@tonydaley3281
@tonydaley3281 2 жыл бұрын
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?
@hisf1shness
@hisf1shness 2 жыл бұрын
Great video, but IMHO it lacks mentioning the built-in functional interfaces such as Producer, Consumer and of course Function. Why? Because these are the interfaces that lambdas will be squeezed into when using stream() with map/foreach/collect.
@jeremychilvers2382
@jeremychilvers2382 2 жыл бұрын
Yeah....but why. Unit testing? If you want to script use JavaScript . If you want to write clear concise code use Java. Why muddy the waters with lambas? Maybe provide some real world examples for context.
@kevin_mitchell
@kevin_mitchell Ай бұрын
1:48 "But also we have down here we have this method printThing." With all the boiler plate code auto-generated by IDE's, maybe you should clarify that you created this method as opposed to it being auto-generated when the IDE created the interface, because that's how it-comes across as, "Oh surprise surprise, look what we have down here, a method printThing. I wonder where that came from?"
@OlliS71
@OlliS71 Жыл бұрын
Java Lambdas don't have state. I wish Java would implement Lambdas like in C++ with captures; this would make Lambdas in Java much more powerful.
@Jaksteroide
@Jaksteroide 5 ай бұрын
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!
@GeloEd
@GeloEd Жыл бұрын
If I am getting it right, you can use lambdas only on functional interface(with one abstract method). You can use it with multiple abstact mewthod only if you are using inner classes? Will rewatch the video again to capture it fully :)
@elairyx
@elairyx 2 жыл бұрын
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 :)
@TusharDwivedi19
@TusharDwivedi19 2 жыл бұрын
at 1:55 . static void printThing(Printable thing) . how we are giving that Printable and thing as parameters , what does this thing called, because I learned we can give like for example "public void customer(thing, something){} as parameters . like passing it. I don't know if I'm explaining my question right. if anyone understands please help me with this concept.
@shubhamtandon5191
@shubhamtandon5191 3 ай бұрын
@CodingWithJohn please do a video on Predicate, Function, Consumer, Supplier
@cyberkiller83
@cyberkiller83 2 жыл бұрын
Correct me if i am wrong, but according to this valuable info, a Lambda expresión is justa fast way to create Anonymous objects with only one method? I mean because, you can create a interface that specifies 2 methods and then when you are instantiating anonymously, you have to implement the methods at the instance... just like a lambda. like this: interface test{ void method1(); void method2(); } public class Principal { public static void test1() { new test(){ @Override public void method1() { } @Override public void method2() { } }; } So the interface stop being functional as it has two methods, but you can still use it with anonymous instances... so the only difference with lambdas are... there are less code involve on the instance as i see.
@geeta774
@geeta774 2 жыл бұрын
Can you make a video on all assert methods like assertArrayEquals(double[]expecteds,double[] actual,double delta and for all assert methods,will you provide example of positive and negative test case
@JohnFaire
@JohnFaire 2 жыл бұрын
Thank you for these videos I am a first year student of an online university and I feel your videos are very good. I wanted to tell you t hat I have to slow down your speec h this is because you sta rt your sente nces without pause like a run-on this is difficult to process because points are made to be proc essed I often have to stop and go back to follow alo ng it's like having a sentence read without a using punctuatio n or taking pause to reflect on the un derstanding o f it all. For me, your points come across better where speech is slowed down, to make up for how you edited your audio/video when your sentence, or idea, ends. The way you articulate is fine, and clear, it's only when you edit in your new topics that your sentence structure gets ran off. This makes it harder to watch your videos. I left your videos, originally, looking for better instruction because of this. But now, I find your videos to be consistently better organized and to the point than others. Really good job. So, I slow you down, and re-watch everything, until I learn something. To add, you could try comparing your screen to other KZbinrs. Yours is big. Sometimes the code doesn't show unless you horizontal scroll, which you forget sometimes while you are explaining. Maybe zoom in a little. We have no problem making you bigger with the full screen button here on KZbin. So font size isn't really an issue for us. Lastly, you switch back an forth, as you have to in Java, between classes/tabs. This, for me, is what makes Java confusing in the first place, unlike python, etc. More often than not, you don't reference by name which class/tab you are switching to. Instead, you say for example, Now we are moving over here" Where is here? There were four classes open. Where'd you go... kinda thing. The problem with your speech running on and not knowing where "here" is make us have to stop to video, rewind, and re-watch the top portion of your screen to know where here is. Then, re-wind again to make sure we understood the point between you moving the "here." I thought I should share my thoughts because I could see some students leaving because of these things, and I don't think they should, as your content consistently good, and thorough.
@fallennarcotic6981
@fallennarcotic6981 2 жыл бұрын
I have the annoying habit to break my head over questions that are answered in the video if I just watched it further but instead I pause and literally let my brain melt over a question like: how the hell does java know which function to use If we have several abstract ones. Then comes John and voila. IT DOES NOT! :)
@aeronespina7680
@aeronespina7680 Жыл бұрын
Lambda Expression looks like arrow function with callback implementation in Javascript.
@backtashmohammadi2231
@backtashmohammadi2231 Ай бұрын
I am really impressed by how good you explain each method. THANK YOU
@ankitdedhia1105
@ankitdedhia1105 2 жыл бұрын
Hey John, Loved the explanation. One thing I wanted to learn was the concept of the Effectively Final variable in the context of Lambdas, with the logic behind it. Why does it work that way?
@StillAlekh
@StillAlekh 2 жыл бұрын
Please do JVM, JDK, JRE. I have been coding since 2 years yet struggle to understand it. Please help.
@ilyaJUNiOR
@ilyaJUNiOR Жыл бұрын
My English level a2-b1 but l enjoy watching your videos 😊 Thank you for your hard work.
@tkariclook
@tkariclook 2 жыл бұрын
Nice tutorial) practiced listening in english, repeated Lambda in Java. But I work on Scala)
@maksimmukhin6175
@maksimmukhin6175 2 жыл бұрын
This is not completely all explanation about Lambda contains in this video. What about short variant of Lambda expression record? There is exist a way to write something like that: param::method. It have a less information and heavy to debug, but it is!
@MaryamMaqdisi
@MaryamMaqdisi 2 жыл бұрын
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!
@Meleeman011
@Meleeman011 Жыл бұрын
wow imagine if lambdas were in php, then we could get rid of all the interfaces and traits and just just lambdas, and then Laravel would be simpler to maintain. too bad java doesn't have a laravel like framework for the web.
@sergiuszwinogrodzki6569
@sergiuszwinogrodzki6569 2 жыл бұрын
13 minutes to explain lambdas. Man. I have a quicker one: lambda is like an arrow function in JS. Cheers
@biredoffreedom2917
@biredoffreedom2917 2 жыл бұрын
Thank you (meow) for your explanations it was so clear and meaningful(meow)😅🤣😂
@furrball
@furrball 2 жыл бұрын
sooo... y-you first isolated the implementation, such that it stays in one place, then you brought it back in raw form where it was called, which defeats the purpose of encapsulating it in a class, THEN you re-isolate that in a reusable function passed as an expression. Great. Any other ways to pass time or do you ever get to code?
@krzysztofs551
@krzysztofs551 2 жыл бұрын
Great tutorial as always but I cannot reproduce the way you use lambda with the return type. I see the Cat object is disappearing somewhere, the method that must be overridden in Cat class is not updated when you change params quantity etc. I watch two times and cannot reproduce this simple task. I try to do slowly step by step with you.
@prajwalgowda9078
@prajwalgowda9078 2 жыл бұрын
1) How are you taking the object as parameter of an Implemention class in the print thing method? We are not supposed to create an object of implementation class, right? 2) and why are you creating an extra method like print thing, please explain , I'm not able to understand
@matimozg
@matimozg Жыл бұрын
Thanks, man it's very helpful explanation of this topic. I needed help with return type lambda implementation.
@christianbarnay2499
@christianbarnay2499 7 ай бұрын
You don't need to implement an object of the class in the first place. You just need to define the method as static and call it directly with no object instantiated. Lambdas are just a lazy obfuscated solution to a problem that doesn't exist. And they are a nightmare in maintenance because nothing is named and everything is packed in a single instruction. You can't debug a lambda without converting it back to the exploded version. I've been there. I had a colleague who wrote lambdas for 2 days because lambdas are cool and fast and easy. The tests gave several errors and he was completely unable to debug it himself in 1 day. He called me to the rescue. First thing I did was to rewrite all his lambdas as regular static named functions with named parameters. It took only half a day and after that it only took a couple step by step runs and all the errors were found and corrected in less than an hour. Since then I forbid lambdas in all my projects. And I'm still waiting for someone to prove me that lambdas can do things that can't be done with plain old regular functions.
@agent5420
@agent5420 2 жыл бұрын
But what if we had Cat, Dog, and Pig? We would do lambda expression for each and every animal?
@Blaze-uj7bg
@Blaze-uj7bg 2 жыл бұрын
Ty for the many tutorial it really help me so much
@hmzza1
@hmzza1 Жыл бұрын
With more than 20 years experience in Java programming, you really explain advanced topics so simple!!
@babonneau
@babonneau Жыл бұрын
I thought that it was going to be a music tutorial from the background in your first seconds of video! Cool to watch a clever Java tutorial from a developer also playing music ;-)
@annalee9763
@annalee9763 2 жыл бұрын
how to connect two statements and then read it into a file or write it into a file for example -> storing the output of this programme in a file package com.example.mysmsapp; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import android.Manifest; import android.content.pm.PackageManager; import android.os.Bundle; import android.widget.TextView; import android.view.View; import android.widget.TextView; import android.database.Cursor; import android.net.Uri; import java.io.File; import java.io.StringReader; public class MainActivity extends AppCompatActivity { private TextView myTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myTextView = findViewById(R.id.textView); ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_SMS}, PackageManager.PERMISSION_GRANTED); } public void Read_SMS(View view) { Cursor cursor = getContentResolver().query(Uri.parse("content://sms"), null, null, null, null); cursor.moveToFirst(); myTextView.setText(cursor.getString(columnindex :12)); } }
@saravanaljku510
@saravanaljku510 6 ай бұрын
00:03 Lambdas in Java 01:41 We can create a cat object and call the print method on it. 03:20 Using lambdas to pass method implementation as a parameter 04:55 Lambdas in Java allow method implementations to be saved as objects. 06:36 The printable interface's print method can take a parameter called 'suffix' 08:07 Implementing a lambda expression for a method with parameters and return type in Java 09:45 Functional interfaces have exactly one abstract method 11:29 Lambda expressions allow implementation of only one method in an interface with one abstract method.
@selokamakola2321
@selokamakola2321 Жыл бұрын
basically these Lambda expressions are like es6 arrow functions in JavaScript
@renomtv
@renomtv 3 ай бұрын
Question: lambdas are meant allow defining the implementation at _run-time_ rather than compile-time, is this correct? My takeaway is java wants to enable javascript-like abilities
@MS-ib8xu
@MS-ib8xu 3 ай бұрын
Almost perfect video... when you first implement the lambda, you should have removed the Cat object to show the audience you don't need it.
@slimandahra4294
@slimandahra4294 2 жыл бұрын
Hello John..thank u so much for this useful video's..i bought your course..but unfortunately no new lessons ..it stops on stream..are you going to make new lessons soon? And best of luck.sliman
@sonad6213
@sonad6213 Жыл бұрын
Hi John, can u plz guide me? which laptop should I buy for coding practice or if anybody can help me with laptop or refurbished good laptop as I cannot afford to buy one.
@mahmad9095
@mahmad9095 2 жыл бұрын
Hi! What makes Java language stand out between all other trendy languages like Python and JavaScript. And why people consider Java as a dead language these days?
@1234567mrbob
@1234567mrbob 2 жыл бұрын
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.
The day of the sea 😂 #shorts by Leisi Crazy
00:22
Leisi Crazy
Рет қаралды 2,3 МЛН
Как мы играем в игры 😂
00:20
МЯТНАЯ ФАНТА
Рет қаралды 3,2 МЛН
The Joker wanted to stand at the front, but unexpectedly was beaten up by Officer Rabbit
00:12
Do you choose Inside Out 2 or The Amazing World of Gumball? 🤔
00:19
The day of the sea 😂 #shorts by Leisi Crazy
00:22
Leisi Crazy
Рет қаралды 2,3 МЛН