In this episode we'll talk about a super useful feature that was introduced back in Java version 8, known as Lambdas.
The Lambda feature is something you didn't know you desperately wanted or needed until you understood it.
The Lambda syntax allows you to write much cleaner and more readable code, while also empowering you to get more done with less code.
In this lecture, I'll be referring to some code that you can download via this github repository.
Hey fellow coder before we rolled into the episode today this one is sponsored by brought to you by the Coders Campus Bootcamp. If you haven't already checked it out, you can check it out via coders campus.com forward slash boot camp. So if you're looking to get a job as a coder, and you've been struggling to achieve that on your own, you are struggling to learn how to code on your own. You're not alone. And that's what that's why these boot camps are so popular. So we'll talk more about that at the end of this episode. But yeah, please do check it out coderscampus.com/bootcamp, you can apply to see if you'd be a good fit. So having said that, let's roll into today's content
Welcome to the coders campus podcast, where you'll learn how to code from one of the best teachers in the industry. Whether you're an absolute beginner or a seasoned pro, the coders campus podcast will teach you what you need to know to master the art of programming.
And now, your host, Trevor page.
Ladies and gentlemen, boys and girls, children of all ages. Welcome back to this 51st episode, I think of the coders campus podcast. Thank you so much for joining always a pleasure to be here in the hot seat and bringing you the important information curated by none other than the No. Okay, so let's focus. So yeah, welcome to the podcast. Great to be back. And I want to kick things off by talking about sort of what I alluded to in a past episode, I forget when I alluded to it. But yeah, I want to get to talking about streams eventually. But before I can talk about streams, I want to talk about lambdas. So today's episode is always good, it's going to be I should say always going to be the full episode will be about lambdas and lambda expressions and lambda, this lambda that you will be by the end of this episode, a lambda expert. So let's dive right in to it. I'll open up my notes here. So I guess the first thing we can start off with is what the heck is a lambda? Why is Trevor talking about this subject? When is it used? Why is it important? Why should I know about it, that kind of thing. So we'll start off by obviously talking about what a lambda is. So it's essentially a syntax that is used to cut down on the code that you have to write essentially, reduce the verbosity is the professional term, if you will reduce the verbosity of the code. So what that means is, you'll have to write less code in order to do the same thing. Okay, that's really, you know, there's a lot more than it can do. But that's, I mean, you know, fundamentally, why would you choose to use a lambda over not a lambda, it's, it's really to reduce the verbosity of the code. And that should tend to lead to more readability case, your code becomes shorter, more succinct, and more readable. Now, the it's a double edged sword. Because when you do this, when you reduce the verbosity, when you abstract away some details, when you hide the inner workings of what's happening through shorter code, although it's more readable, it's only readable if you understand it. So what this this tends to lead to is more confusion if you do not understand it, hence, me talking about lambdas. Today in this podcast episode, so lambdas are very powerful. They were a feature that was added to the Java language as a version eight. So Java, version eight at the time of this recording, is, you know, one of the most, if not the most popular version of Java being used out in the wild. And no, some you know, there's no surprise there's there's a big correlation between lambdas being introduced in version eight and version eights, popularity, lambdas, and streams were very well received, and in my opinion, are great, I absolutely love them. So important to learn about. Now beyond reducing the verbosity of the code with respect to using lambdas. Beyond that, we also it allows us to treat
So yeah, it allows us to treat methods like parameters, sort of, so
basically, get the way to think about this
is in my mind is to look at how we had to do it the old way. And and what we had to do in the pains and whatnot of what we had to do the old way before version eight. And then we can look at what the new way is with respect to lambdas. And, and whatnot. So I do have some code. And I will try to, I guess I'm gonna have to put the code in some show notes for this episode, so that you guys can load it up and look at it. Again, I'm tasked with trying to explain code, verbally, without you guys seeing the code in front of your eyes, which is always as I say, a very difficult task. But if you are not driving, and you're able to, you can go to I guess I'll put it up coderscampus.com/51. As this is Episode 51, you can go there and bring up the show notes. And you'll be able to see an example of what I'm doing. I'm also going to post this or I have already posted this as a GitHub repository. So you can also not just see it on the blog, but download it and play with it. Because that's what all the cool kids are doing these days. So
yes, having said that, let's dive into sort of the code. So the old way of I won't say the old way of using lambdas. But in that's not correct. There were no lamb lambdas in the olden days before Java eight. So how did you do this? How did you work? You know, with these things? Well, basically, what ended up ends up being is you are working with interfaces, and you're trying to
utilize or use an interface by sort of instantiating it. So when you try to instantiate an interface, if you have done your homework, you know that that's really kind of not possible, you cannot instantiate an interface, you can only instantiate a concrete class, right? So you can only instantiate a class. So how can you get around this? How do you get around
the whole you can't instantiate an interface, but yet you kind of can instantiate an interface.
It's done through essentially
instantiating the interface and overriding it. So in other words, you are implementing it right there. And then inside of the code. So an example of this, you probably swatch. And so you probably seen, if you worked prior to Java eight, you will have seen this through the syntax of when you say a new interface. So if you tried to list like a list, or a map, or whatever, and you say new list, and try to instantiate a new list, list interface, or map is an interface, those are not concrete classes, so you can't instantiate them. But what you will see is, if you say new list or new map,
and then you try to, you know complete it, what it's going to do is it's going to open up a body of code, it's going to open up curly brackets. And it's going to force you to override each and every one of the well abstract methods inside of the interface, right? Because that's all an interface is made up of, if you want a quick review of what an interface is an interface is made up of public abstract classes, or sorry, public abstract methods, not classes methods. So an interface is made up of public abstract methods. And what does that mean? What is a public abstract method? It's just a method that has no body. Okay? It has nobody has nobody to turn to terrible joke, I'm sorry. There's no body of the code. So basically, what's happening here is when you try to instantiate an interface, it says, Fine, I don't know what you're doing. I don't know why you're trying to instantiate this interface, you can't do that. So here's the workaround, I'm going to force you to override and create the body of every single abstract method for me, because that's the only way you can use an interface, right? You have to give it behavior, you have to override the code and give it a body. And this is usually done. In a separate class, you have a concrete class that implements the interface, right? You have a class implements the interface, and that class is overriding every one of the methods for that given interface. And you'd have it all in one neat place in one class file. Well, when you do it on the fly, if you're doing it in line, if you will, if you're saying, you know, some if you say list, my list equals new list, it's going to say, Oh, well, we're not going to put this in a different class file. We're just going to make you do it right here in inline in the code right now, next to the new keyword right next to the new list, parentheses, whatever, then it's going to force you to create a body and override everything. So anyway, that's sort of what we had to do in the in the olden days. We would be forced to if you wanted to try to instantiate interface, we'd be forced to override everything and give everything behavior and whatnot. Right there. And then so
So and that's sort of what this code that I have, that you can look at, that's what it's doing. So I have some code called non lambda example. It's just a class. That's called non lambda example, a very non creative name. And the, that class has a method and the method is called add strings. Now, this is not a very real world example, I apologize for that I was trying to make some sort of perfect example. And I don't have all the time in the world on my hands. So I settled on just taking a regular example that you find on the internet, I know, that's not the greatest thing in the world, but I will do my very best to, to give you as much detail around that as possible to make it make sense. So for whatever reason, we have a class, it's called non lambda lambda example, that maybe this could be considered a string, utility class, we'll call it string utils. Right? We can't call it that, because that's being used, but let's just say it's a string utility class. So it gives you some sort of methods that are useful, you know, with respect to strings, okay, allows you to do stuff with strings. That's what this class does. And as part of this class that we're talking about, that does stuff with strings as utilities class,
it has a method called add strings. Okay, so what add strings does is it allows you to add together a couple of strings. So in other words, concatenate strings together, again, not a very real world thing, because we already have a method to concatenate strings, it's just a bloody plus symbol that we can put between two strings. Anyway,
how do we do this? How do we have if we have a method that add strings together,
and let's say we have an interface that allows us to add strings together, this, you know, method could just use that interface, and we can instantiate the interface and make use of it right there. And then, like I said, the side effect is, it's going to force you to override all of the methods of the interface. Okay. So if you can imagine, you know, there's some interface called, you know, I don't know, it's called non lambda interface in my code, but really, we could call it the, you know, string utilities interface or something.
And this string utilities interface has a method within it called add strings together, and it allows you to pass in two strings. And what that does is it will take in two strings and return a string back. So it takes in two strings, string one, string two, and it outputs a single string. Okay, so what is the point of this write it? Well, like I said, it concatenate strings together. And that's just the purpose of this particular interfaces method where the method is called add strings together. Again, it's not very functional, but hey, it's, it just puts a space between two strings, great, fine, whatever. Well, how do you how do you use that, then? Well, you need to, you know, in line instantiate and, and define a body for this non lambda interface, or the string interface or whatever, with this add strings together method, you'd have to implement it by returning the string one and string two with a space together. And then you need to take that interface that you quote, unquote, instantiated and invoke that method, add strings together, and you pass it string one and string two. Right? That's sort of how you would do it, if you did not have lambdas. Now, that was a lot of talking, right? That was a lot of talking to try to describe this. And if it sounded convoluted, and weird, it's because it is, it's convoluted and weird. It is an old way of of trying to
perform an operation of like instantiating an interface, essentially, right? Again, you can't instantiate an interface. But you can get around that by implementing it in line implementing all of the the methods within that interface. And the result of that is that you get a big long block of code that's quite ugly, and whatnot. And it's not very, not very readable. And it's, it's verbose, right? That's the whole point here. So how can we make our lives easier, right? Well, that's where the lambdas come in, right? We have these things called lambdas. And they work alongside this concept called functional interface. So there's an annotation called functional interface. And in my mind, I, I take a functional interface and the concept of lambda and I mash them together in my head, because that's really a funk. You can't use a lambda without a functional interface. Okay? So keep those that sort of, again, take that for what it's worth. It's stored in your brain the same way if you like, but like I said, Before, you can actually use lambdas. Before you can actually write out the lambda syntax, which is less verbose than the syntax that I just tried to explain to you without lambdas in order to use that code, that syntax the less verbose syntax
You need a functional interface? So, okay, what the heck is a functional interface? And why do I need that? Well, a functional interface is the word comes from functional coding functional programming. Okay, functional programming is very much, you know, if you have inputs, or I should say when you have inputs that go into a method for a method signature, you have inputs, for any input that you give it, the output will always be the same, meaning, if you have an interface a functional or functional code, I should say, if you have some sort of functional code, functional programming code with an input that takes an integer, if you pass in the number one, you're going to get a result. Okay, let's say that this particular functional code, the way the way it's written, the method that we're invoking is the, you know, the squared method. So it should take an input of a no a single number, a whole number, an integer, and it should square that number and give that as the result. So that means that when you pass in the number one, to this functional code, this functional method or whatever,
you'll always get one as the output. And if you pass in to what is two squared was two, or Yeah, two squared is four. So every time you pass in two, you're always gonna get four, right out, if you pass in three, you're gonna get nine, if you pass in for you're gonna get 16 525, you know, 636, oh, my God, I'm going back to math class, you know, 749, how high can I go 864 981 10 111 121 12 144 13. And that's where my brain stops. So that's as much as much of the squared,
which call it a multiplication table that I've memorized. So anyway, the point is, whatever number you put in, a result will come out. And that result should never change based on the inputs. So you'll never get a situation where you pass into three, and you get 10. Out, it will always be nine, because three times three, three squared is always nine. That is sort of what functional code is all about, right? predictability? No, there's no
side effects that happen. There's no weird situation that if this one situation plays out around this method, and the methods output will change, right? In other words, that's, that's called a side effect. If, if there's a side effect, something weird happened, and then boom, the output is not what you expected. output changes. That's not good. That's, that's not a very stable environment to working in. And that's, that can happen with with a Java language, we can have side effects, right, we can have, you know, inputs, the same inputs can produce different outputs for a given method, if it's not a sort of functional programming style. So at least again, that's what's that's how I think of it in my brain. I'm sure there's a lot more to it. But hey, I'm trying to be as as straightforward as possible here. So does that make sense? functional code means in the same inputs will are the inputs that you put in will always give the same outputs for each given input. So one will get one two will get four should never change. That's the functional lens, if you will, with respect to programming. So what is a functional interface? Well, it's an interface that provides functional code coding in the functional style. Make sense? So when we have a functional interface that provides well being an interface write an interface means it has abstract methods, public abstract methods,
which all interfaces have, but there is a specific requirement for a functional interface, which is that there can be only one public abstract method in the interface. That's it. You get one ladies, gentlemen. So that's sort of the the behavior that is the stipulation the specification for a functional interface. In the world of Java, you have one and only one public abstract method. Now you can do more than just a public abstract method. You can have default methods. I think we've talked about default methods in terms of Java eight, introducing the default keyword.
Anyway, let's let's stick to the basics, though. Have you have one public abstract method, and that is it. Okay. So in my code that I've introduced here, I've given you an example of I just called the call it the lambda interface. And again, these naming conventions just to show that one is lambda one is non lambda. But really, if I were to name this properly, this lambda interface might be called something closer to
Yeah, the string utility interface, right? Or maybe functional string utility interface, or I guess you wouldn't call it functional. That's, that's not true. That's, that's a bad convention. I would just call it string utility interface or string utilities or whatever. You annotate it with the functional interface annotation at the class level, or at the isn't, that's not the right term. Because it's not a class, what would you call that? I always call it class level. Interesting. at the root level, what anyway, again, you'll it's at the top, it's right before the declaration of the interface. So at the interface declaration level, anyway, you use functional interface, it comes from Java, as part of the what java lang. So it's very, it's built right into Java lang, which is like the root, you know, package, if you will. So we have we declared as a functional interface. And all that does is it enforces the single public abstract method.
requirement. If I right now I'm typing in another piece of code, I'll type in like, you know, add another string or something, and I'll have another,
you know, method, the public abstract method. As soon as I do that, when I have the functional interface annotation declared in here, it gives me a compilation error. So the interface goes red, and it says, Hey, invalid functional interface, annotation. lammed interface is not a functional interface. In other words, because I've added a second public abstract method, it is complaining, so I delete, you can't see me delete it, but I've deleted it. And now it's back to just having one method in there. And now it's happy again. So that's what functional interface, the functional interface annotation gives to us is sort of a compile time check to make sure that we are adhering to that single, abstract method requirements. So having said that, why is this why is this helpful? How is this all this stuff that I've talked about, about functional coding and functional interfaces? And one single abstract method? How is this going to help our code be more readable? Well, that's where the concept of a lambda actually comes in lambda expressions or whatnot. So inside of our interface, we have a single method, and we call it add strings together, just like what we called it in our other interface that was the non lambda interface, we had an add strings together interface, or sorry, add strings together method inside of a interface. So in terms of how, what the interfaces look like, they look identical, okay, the the non lambda interface versus the lambda interface, the code is identical, except for the the lambda interface has that one extra
annotation called the functional
functional interface annotation. So in the interface level, nothing changes other than that annotation,
and the rules that come with it. Now, what does the the rest of the code look like? Right? What is my example code look like when I want to use the functional interface.
And this is, again, the I don't say, once again, this is the first time I'm saying this.
The code that I've written that I'm sharing with you, and that I'm talking about right now, is probably not code that you're ever going to actually write. In the real world, at least most of it you won't write, generally speaking in the real world out there in the wild, you do not create your own functional interfaces. Okay, the purpose of this episode, and the purpose of the this exercise, if you will, that we're going through, is so that you get a fundamental understanding of how the inner workings of a functional interface actually works actually functions, for lack of a better term. But just so you know, the caveat here is that you probably won't ever create a functional interface. I mean, you might, but you probably won't, because Java provides a bunch of functional interfaces for us. And we will get into what those are. And the common ones that you'll see out in the wild, we'll get there in in a little bit. Well, how long has this episode been? Do I need to split this up into two? Oh, my God, it's already close to half an hour. So maybe we might talk about that in this one, we might push it to the next one. So just keep that in mind. But for now, I want to teach you how to create your own functional interface and then use it right cuz that's what this is all about. So, in our lambda example, class, we had a non lambda example class where I talked about having the add, you know, add strings. Method, which instantiated quote unquote, instantiated the interface, which forced us to override it and do all the body so everything I talked about already, and then actually invoking it, and using, you know, the stuff that we had to override everything. That was the old way. So the new way, how do we use it? Well, we same kind of start, we say lambda interface, right? So we declare, we declare a variable, the type of the variable that we're declaring is going to be lambda initial
phase, which is the interface that we created. Again, a better name for this would have been string utilities or something.
But we're trying to be lambda forward here. So I called it the lambda interface as the type. And then you declare a variable name, the variable name can be whatever you like. It's just a variable name. I chose functional interface as the variable name. Sure, fine. So we have a functional interface variable with the type lambda interface. Okay, which is an interface, it's not a concrete class. So therefore, we can't instantiate this right? What do we do? Well, we can set it equal to
a lambda expression.
Okay, I don't even know if that's the right term, I think lambda expression refers to the stuff on the right of the lambda, I don't know what the word is to represent the entire thing. But
basically, instead of having to declare a big body, you know, having the curly bracket with a new keywords a new lambda interface, and then having a curly bracket to open the body, and then overriding the single method inside of it with functionality and saying, all that stuff doesn't have to happen.
We take all that stuff, and we boil it down into two things, I guess, sort of three things. But the third thing is simple. Two things, two parts. Okay, and this is where the verbosity goes away, then this is what I'm about to talk about. This is the syntax involved with the utilization of lambdas. Okay, so this is what this is where the rubber meets the road, ladies and gentlemen. So
we will, we will use this lambda
syntax to assign functionality to our lambda interface type that we're this variable that we're creating, okay. So
because the functional interface, or the lambda interface only has one method inside of it, by design, it can only have one public abstract method.
Java knows what the method signature is for that single public abstract method. It knows it already. Okay, it's too we have to we had two inputs for this one. So to go back to it just because you're not staring at the code in front of you. The lambda interface method that we created, the public abstract method was called add strings together. So add strings together with the lambda interfaces method. And the add strings together method has two inputs, s one and s two, which is strings. One, S S, one is a string, and S two is a string. In other words, add these two strings together concatenate these two strings. So probably a better way a better name for this function or method would have been, not add strings together, but rather concatenate strings together. But anyway,
I this is this is the code that I've written ladies and gentlemen, this is what we're dealing with. So it has two inputs, two strings, and one output one string as the output. Okay, that's what the method is declared, there's no body in it. Because it's an abstract method. abstract methods don't have bodies, it's just a method signature, takes two strings in one string out, okay, that's what this adds strings together. thing does. And because it's a functional interface, because we've declared it as a functional interface, Java can do some fun stuff with that. In other words, it can abstract away some, some syntax and some details here.
So because we know
the method that is the functional method, the you know, the single abstract method, we know the specifics of it, we know the the method signature for it.
There's, like I said, there's two parts that kind of are three parts, but there's two parts to the syntax, there is everything to the left of the arrow, and everything to the right of the arrow. Okay, the arrow is the third thing. So the arrow is the syntax that you look for, that's the smell, that's the indication that we're using a lambda. So in the world of Java, the new syntax is this arrow, which is the minus sign followed by the greater than symbol, which looks like an arrow, an arrow pointing to the right, minus greater than picture that in your brain right now I'll take a sip of water.
it is a minus sign with a
have greater than next to it. So that's the arrow. And that's the third thing. So there's everything to the left of the arrow, and there's everything to the right of the arrow is what we're dealing with. To the left of the arrow is the method signature. So this method signature, if you were to type it out, you would, you would just have
just the, I should say, just the parameters of the method signature. So we don't even need the name of the method here, we don't need the return type, we don't need the name, we don't need anything other than the parameters. So a better way for me to say that is, the stuff to the left of the arrow is just the parameters, the list of parameters, and you can type it in as string s one comma string s two, if you wanted to, because that is literally if you caught if you went into the declaration of the method, and you looked at the parameters for the method in the functional interface, that is exactly what is written copy, paste, it's the round bracket, string s, one comma string s to close round bracket, that is the list of parameters, you know, surrounded by the round brackets, the parentheses, parenthesis, parentheses, whatever.
That's everything to the left of the arrow. Okay? Now, because we can want, we can also be even less verbose. And because we know that this is a functional interface, and because we know there's only one public abstract method, because we know the method signature already, I say we Java knows the method signature already, it knows the parameters, it knows the types, so we don't actually have to write in the types either, we can literally just write round bracket, S, one comma s two, round bracket.
And believe it or not, we don't even have to call it s one and s two, if we don't want to, that's what we called the variable names of the inputs in the function in the interface, right in a lambda interface. That's what we call them. But we don't have to call them that we call it a one and a two or x one and x two, or X and Y or whatever, dog poop one and dog poop two, right? So that's, we can name it whatever we want. So for this one, I just kept it consistent with s one and S two. But just so you know, you can call it whatever you want. Now, everything to the right of the arrow is where things get pretty cool. So we have a few choices here to the right of the arrow to the right of the arrow is essentially the body that you are going to give to it right everything to the right of the arrow is what we have declared and written already in the non lamda example. In the non lambda example, we had to remember open up the body and the curly brackets, we said new you know interface with open up the brackets, and then we had to override the method. And then inside the method, that method had a body to it. This is the body that we're talking about. So we can take what's inside that body, the curly brackets inside the body that so the curly brackets and there was a return statement, saying return s one plus a space plus s two.
Right? That's what this does it concatenate two strings together with a space between them as one plus a blank space meaning double quote with the space double quote, plus s two, that's how you concatenate was one way to concatenate two strings together with a space in the middle s one plus space plus s two. Okay. So if you just look at the body there, it's curly brackets with a return statement returning that s one plus space plus s two.
So you can just copy paste that body into the right side of the arrow.
Syntax. Okay. And then you're good. That's that's pretty much it. But
Because we are returning something and because most times, in the bodies of methods, we're returning something, there's a special shortcut to make this process even less verbose. You can get rid of the body indicators, the body, the curly brackets, the opening and closing curly brackets, get rid of them.
And you can get rid of the return statement, the return I should say the recruiting return keyword, just that return keyword and just have everything to the right of the return be copy pasted it to the right of the arrow. So in other words,
your lambda interface, which I called the variable name, functional interface equals right when you're setting when you're, you know, in the old way, we had to say lambda interface or whatever the other interface is, you know, string, let's call it string utilities, you know, is the interface name and then we call it string. utils is the variable equals something and we had to say equals new in the old way, string utilities and then overriding all that stuff and all that complex stuff.
With this new way, we can say you know, your string utilities, you know, string utilities, whatever equals, in this case, again, it's not string utilities. It's lambda interface, but
Anyway, trying to connect it to the real world a little bit here, the equals everything to the right of the equals is just
open round bracket s one comma s two, right, which is sort of the variables, the inputs, without without the variable types, s one comma s two, it knows that these two things are strings already, we don't have to specify their strings, we can just surround them s s one comma s two, we can surround it in parentheses, put the arrow my assign greater than symbol. And then to the right, we just type in S one plus space plus s two semicolon.
Okay, so it's literally one line of code. I know, there's a lot of talking there. But there's a lot of teaching too, is literally to to declare the interface and to declare the functionality of the body of the interface is all done within one line of code.
So we've taken this interface. And we've kind of instantiated that we've kind of set it equal to something and given it behavior, we've given it the behavior of taking a string as first string as an input and taking a second string as an input and concatenating them together with a space. Okay, that's the functionality that we've defined, we've defined this method. Now, this method technically has a body. But it's still just a method, we haven't invoked the method yet. It's just there. And it could be used if you wanted to use it.
So now in order to use it, you need to say your, you know, variable name, which I named it functional interface. So again, probably could have chosen a better name, but hey, functional interfaces, dot and if you remember the name of the functional interfaces, single public abstract method, do you remember the name probably not, it was called add strings together is my an imaginative name for it. So you do functional interface dot add string together. And what it expects is two inputs, two strings, so you just type in the two strings, right? But whatever two strings you want, that you want to have concatenated together with with a space, and voila, you're off to the races. So in other words, you know, probably, you know, five or six lines of code go goes down to essentially two lines of code. Right?
Cool, fine, great. Grand, why? Why do I care? Why is this? You know, we went through all this, it's been how many minutes now that I've been talking 36 minutes, 36 and a half minutes?
Why is this important to talk about. And to understand? Well, lambdas with the land, when I say lambda, you can think arrow syntax, you know, the arrow syntax of minus sign with a greater than symbol, you know, method parameters in the left body on the right, if you don't have parentheses, if you don't have curly brackets, then it's assumed to be a return statement is gonna be returning the stuff, if you don't want it to return something, or if there's more logic you want to put into it, then you declare the squiggly brackets to actually give it a body explicitly give it some sort of body functionality. But anyway.
lambdas, as I just described them, are used as a part of a bunch of different things now in in Java, any sort of functional programming that you can do in Java. Now, as of Java eight and beyond? They all make use of lambdas. Okay, because there's properties to these lambdas that enforce functional behavior, one of which is anything you use on the right hand side of the arrow has to be final, or it is it is in what's implicitly, yeah, it's implicitly final, which means you don't explicitly declare these variables that you use on the right hand side as final. You don't explicitly declare them as final, there's no explicit writing of the word final in there. But if you try to
or reassign any of the values of the variables on the right hand side of the of the syntax or whatever, inside of the quote, unquote, body of the lambda expression, if you try to do any sort of non final behavior in the right hand side, it's going to give you a compilation error. I guess remember, we can't have side effects here.
Okay, what comes in whatever you know, inputs come come in. Whatever inputs you give in there should be a dependable and expected output for each input. Again, pass in one get one out, pass and to get 4395. Or sorry, 416 525. Right? If we're talking about squaring something, right, if the if the method in the functional interface was called squaring integers or something,
the behavior and the output should be dependable and expected. So one way to enforce that is to make sure that all your variables that you're dealing with are final
That's a little property a little, a little side effect of using functional interfaces pun intended, is that your variables are final, and that can come up and bite you in the butt. Sometimes you'll be using, you know, lambdas inside of a functional interface or whatever.
you try to do something where you reassign a variable, and it says, Nope, you can't do that. It's final. And it's like, Oh, that's right, I can't have to think in a functional way here. So that is one thing that you need to be cognizant of be aware of. When you're dealing with lambdas, the stuff on the right is effectively final, the variables are effectively final. So the variables, by the way, are the stuff on the on the left hand side, the inputs to the function, that you are working with the inputs to the lambda expression on the right, the inputs come from the left, okay, and then they are later, you know, injected via using the actual interface itself. So anyway, we'll get there, we'll get to more examples to make that a lot more crystal clear. I, as I'm explaining it, I can tell it's not that part is not clear, there's a lot more to this.
So but what you need to take away right now from this talk, is that there is a way to define the behavior of the body of interfaces, interface methods, okay, there's a way to define behavior of interfaces methods,
such that you it can be done in a non verbose way. So in a non verbose way, you can define the body functionality of interface methods.
So prior to Java eight, that just there just was not any simple way to do this, there was not any non verbose way to do this. So that
the big The other thing to say here is you don't have to use lambdas. Right? You don't have to, you don't have to make use of any of the new fancy, you know, shiny methods, and you know, utility classes and stream, you don't have to make use of any of this stuff, if you don't want to, because all the stuff can be done. Without the Java eight stuff, at least as far as I know, you can do all of it without Java eight, you can do all, you know, everything you could do in Java seven, you can continue to do it that way that you could do it, you know, you can continue to do it the way you always did it, right. It's just this newer way is just a little bit more readable. This is less verbose, it's, it's a little sexier. Right? That's, that's one of the jobs that people take at Java, it's, oh, it's such a verbose language. Well, you know, little by little, they're cutting down on a lot of that stuff. Now, again, the side effect of that is, again, pun intended.
You're hiding details, you're abstracting away the details, as you become less verbose as you type have to type in less code, more and more is hidden under the covers, more and more is required of you to understand
explicitly understand what's going on under the covers for you to be able to use this with confidence, right? Because if you didn't know what lambdas were, and you just saw this syntax with these arrows, like this is arrow all of a sudden, and what looks like potentially the parameters of a method, but I don't see any types. And it's like, we have to know what the types are by knowing that it's coming from the interface, the single method of the interface and had to look at that interfaces and look at the type and like, it could be a generic type. And we haven't talked about that yet. And so there's a lot of stuff that you need to understand about lambdas before you can feel comfortable reading them and understanding them and using them. Otherwise, it's a bunch of guessing going on. So while Java gets a bad rap for being verbose, it's also believe it or not, it's helpful from a learner's perspective, when you're fairly new to programming. Having a verbose language is helpful, because you can see all the details in front of you. I don't want to say nothing is hidden, but a lot of stuff is in front of you, and not very much is hidden in the world of Java. So pros and cons. So there you go. That's, that's
I don't wanna say in a nutshell, because I took a while to explain. That's the your first
soiree into utilizing
lambdas. And the syntax behind them. And what I haven't talked about is, there are again, in the real world, you don't really create your own functional interfaces, there's already a bunch of functional interfaces that you can read, reach out and use, and that should,
you know, solve pretty much all your problems that will ever come up to solve all the use cases that you can think of. There are some functional interfaces that Java has provided to us that we can leverage that are, you know, utilize generics and allow us to use them in a very flexible way. The downside to that
It's very difficult to like, understand when you're reading just documentation and hovering over things, it gets convoluted. And we'll get there. We'll talk about that. Which is why it's important to understand what are the common functional interfaces that Java has predefined and built into Java eight, and is handing us to use and leverage? What are those common functional interfaces
that we can leverage? And and let you know, we should get a good understanding of them so that we feel more comfortable. If and when we run into a situation where it comes up in some documentation. And it's talking about the consumer interface functional interface or the supplier functional interface, or the unary operator functional interface or the function functional interface. You might be saying, What the heck is Trevor talking about? Exactly. I didn't know any of this either, before I actually did a deep dive and had to force myself to learn this stuff. And then I was like, oh, okay, now that sort of makes sense. Now, I can start to, you know, put some some of this stuff together and get a better understanding of how it works in the real world. So, hey, I do the struggling and I do the painful stuff of educating myself, so that you don't have to, you can get it in a nice, plain English way. So we will inevitably dive into that now in the next lesson, because there's a lot of talk about and we're already going long here. So I will stop talking there. And we can learn all about the common functional interfaces that Java has predefined and given to us in the next lesson. Now, before I go,
I forgot to do a pitch to you. shameful, shameful, Shameless, self promotion, maybe shameful. This is a shameful plug. Sure, why not?
Boot Camps, ladies and gentlemen, you heard me talking about them. I've doubled down on boot camps, because I am a believer in that system. If you haven't already heard me talk about it in the last, I don't know, five episodes.
I'm very bullish on boot camps. And I'm very proud of the curriculum that I built inside of the boot camp that we are running. And we're launching new cohorts every month now. So we're doing it monthly. We used to do every quarter. But now I'm getting my processes dialed down and I've hired staff. I have code reviewers, I have another instructor that's kind of like a copy of me, and who are in there in the trenches and helping out helping me out to help train the next generation of Rockstar coders. That's my goal here is to help train the next generation of coders.
And I do it with love, and with as much gentle kindness as I possibly can. But really, this bootcamp requires people who are dedicated now if you're already this deep into the podcast, if you if this isn't the first episode you listened to, if you're like, 50, some odd episodes deep into this, and you've been following me for years, yeah, you're probably what I'm the person I'm looking for. If you're looking to get a job, and you've been learning on your own, and you feel like you're understanding the basics, and you're understanding maybe some of the less basic stuff, the more advanced stuff, but you're still feeling very lost. Or you're just feeling like there's no way you'd be ready for the real world and an actual job in an interview situation. Or you're just feeling like you maybe you've done college and you're still struggling to get a job or, or you're thinking about changing careers or you know, whatever your situation is, if you truly want this, if you enjoy coding, if you enjoy learning, if you find learning fascinating if you find learning about coding, fascinating. And all you want to do and all you daydream about is getting a job in this field and getting the job security and all that like I want us to I want to talk to you, I want you to apply to my boot camp. If any of this is resonating with you, I want you to go and apply to boot camp, you can apply via cod erscampus.com/bootcamp.
In there, you'll be able to
find a link or a button somewhere you can say apply now and fill out an application.
But yeah, if you already have a little bit of knowledge, if you are driven if this is your passion, if this is something that you lose sleep over and you stay up late at night, like learning this stuff. And like I said dream, like dreaming about it like this is these are my dream students. For me. These are the people who I see succeed. I want you to go and apply. Because I'm very confident that within six months, we can be having a conversation about getting you a job and having you placed maybe within the next month or two. So total from start to finish. Maybe eight months. You're working in a job as a software engineer, okay? I don't say that lightly.
There are some people who say that they say, oh, you know, learn to code in three weeks and get a job. And you know, that's highly unlikely. I've been doing this for years now I know the pain and struggles that go into learning this stuff.
Those people are people who, you know, someone who could do it in a couple months or something, they have a lot of pre existing knowledge, a lot of training, they probably already have a degree. And we're right on the cusp of getting a job anyway, those are the people who could do it in a couple months, when you're fairly new to this and don't have much experience. If you know the basics. It takes a good six, it probably takes more than six months, but I try my best to cram as much as I can into six months. But yeah, if you have the drive, if you have the interest, and you've been sticking in there, and you've been learning this stuff and dreaming about it, I want to talk to you go to coderscampus.com/bootcamp and apply.
I think I could change your life. Okay, I mean that. Now, if you are someone who this is like, you know, you've been thinking about it for a month, maybe you've been working at it for a month or two. And you're like, oh, you know, this coding thing sounds interesting. And like, I probably you're probably still too too soon on the journey. If you have no experience at all. Yeah, you're way too soon, you know, you have to sign up for you know, listen to the rest of this podcast a few times or something, then maybe not a few times, but listen to the rest of this podcast before you apply. If you've been at it for a month or two,
you might still be too it might still be too soon for you. Unless you are unless you just have a gift. Some people are just gifted. Some people I've seen, they've been at it for a couple months, and they just get it and it clicks. And but those people are pretty rare. If you if you self identify as a very smart person, yeah, maybe after a couple months, you can apply and do well, we'll see. Either way I want to talk to you. And this is how we get to talk to each other, you can book a call to speak with me or one of my admissions advisors. And we can figure out if you're a good fit for the boot camp, right. And vice versa, if the boot camp is a good fit for you, okay, we have financing options now, so that you don't have to pay for the boot camp. Before you do it. I would highly recommend you do because you need skin in the game. But there are ways to get to the point where you can literally pay nothing. Now you need to be a US citizen and you need to have good credit and blah, blah, blah. But yeah, you can get to the point where you can literally put nothing down and take out the loan, do the whole bootcamp and then you don't start paying until after the boot camp after you've graduated. It's possible, right? You can do that. We have income share agreements, where Yeah, I'm sure if you haven't heard of income share agreements already. There, they're a little bit more convoluted than a loan. But essentially, you pay a deposit upfront, not the whole thing, maybe 20% upfront. And the rest, you don't have to pay until after the boot camp after you've graduated. And after you have employment, making a certain amount per year, etc, etc. And you pay a small percentage of your salary back to pay off the boot camp anyway, that's what an income share agreement is all about. Again, these are ways to get you in if you can't afford the tuition. Currently, as of the recording of this, the tuition is 9800 US dollars, it's a lot of money, I get it. But this is an investment. And if you are someone who looks at 90 $100, and says there's no way I will ever pay anyone that kind of money
to get what I want in terms of my dream, in terms of a job that's going to pay me many, many, many, many times that amount that you're investing, if you're someone who's making $30,000 a year, $40,000 a year or $50,000 a year right now, if you're making $50,000 or less per year, maybe even 60, less 60,000 or less per year, you will make back the $10,000 within one year, and then nothing but profit afterwards. Anyway.
That's me getting on my high horse getting upset with people saying I'm not gonna pay you $9,800 Are you crazy, that's now I'm going to go do an online course well then go do an online course. Go pay $10 for something. I just know, I've been doing this for 10 years. And I know what it takes to become a successful self taught developer with a with putting practically no money as an investment into yourself. I know how hard it is and what it's like you have to be in the top 5% of human beings to get to the point where you can pull that off. Okay. And even then you might not do it in six months or less, you'll you might it might take you a year or two. And then you might as well have just done the bootcamp because it will literally be cheaper anyway. So this is going way longer than I anticipated. Apparently I have a lot to talk about. So the bootcamp is here for you. The bootcamp is a perfect fit. If you're dying to get into the tech world and you want to be a coder and you want to have me there beside you as a mentor to guide you. You want to have daily calls with me. You want to have slack access to me and my staff. You want to get code reviews, you want to get a job guarantee. You want to achieve the goal that you're setting
To achieve, which is you're learning how to code so that, probably so that you can get a job date, most of my listeners are in that position, if you already have a job as a coder great. Some people I've spoken to just want to level up their skills, they're stuck in like Java five world and they want to level up like Java 11. Plus, sometimes there's a good fit with those people. But most of the people who I who are interested in in learning and learning from me right now are doing so because they want to get a job. So if you want to get a job, I have a tried and true predictable curriculum, syllabus, whatever you want to call it, and path that you can follow along with me.
And learn from me in all of the ways that you might be missing right now. Because there's a lot more than just learning this stuff. There's so much emotional support around, there's so much extra that's needed, at certain points of your learning journey, that you just don't get outside of a boot camp. You don't get that support. You don't get that shoulder to lean on and cry on when you are so frustrated with some random thing about coding that is just not clicking for you.
Right, that's what you get in these boot camps. So there's a lot there's a lot to the tuition. There's a lot to the whole program, and I'm very proud of it. And I would love for you to apply if you haven't already. So coderscampus.com/bootcamp, we'll get you in the door. Boot Camp is all one word BOTC a MP. Hopefully I'll see you applying soon. And I look forward to talking back at you in the next episode when we'll dive into the rest of this fun, functional interface stuff. So take care of yourself. Happy learning. And bye for now. Thanks for listening to this episode of the coders campus podcast. But before you go, Trevor has a favorite ask you. In order to keep these episodes free, he'd love for you to leave a rating and review the podcast on iTunes. Just go to coders campus.com/review to leave your own rating and review of the show. So if you have 30 seconds to spare right now, please help out by leaving a rating and review via coders campus.com/review It will ensure that you continue to get these awesome free podcast episodes each and every week. So if you like free swag, head on over to coders campus.com/review Happy Learning
Transcribed by https://otter.ai