Welcome back, Scott Stanley here. In these lessons we're going to take a look at imperative versus declarative programming, Lambdas, functional interfaces and higher level functions. So in this lesson, we are going to take a look specifically at what is imperative programming? What is declarative programming? So we see here, there are a couple of different programming paradigms, a couple of approaches to solving programming problems. The imperative approach has been around probably longer. It defines a program as a sequence of statements that change the program state. So you typically have working variables and loops and typically a fair amount of code. Whereas declarative on the other hand, is an approach that expresses the logic of a computation without describing its control flow. It's sort of like declaring what you would like to have happen and just having it be so, whereas imperative is roll up your sleeves and write a fair amount of code. And then they want us to make sure that we see here that a function should return a value based only on the argument and it should have no side effects. I mean it's the textbook definition of a function. Typically when we're talking about declarative programming, function is the next thing that we're gonna start to speak about so. We have a list of Student type, four students I guess Scott, Tyler, Chris, and Edward. And then before each test in the J unit suite here we'll end up with a brand new list of students for each test. So this way, there's no residual between running tests. The tests are totally independent this way. So that's that. The first thing we look at is a search which is using the imperative style. And so we're gonna loop over all of the students and we're trying to determine if the one that someone is looking for, in this case, they want to know if Eddie Van Halen's in here, they want to know if it exists. So there's our Boolean 'found = false', so we'll start off pessimistic. No, it doesn't exist. And the ID that we wanna search for is number four. So there's our loop. The first thing we'll do in the loop is say does this student ID equal the one to search for? If so, we say found equals true and we break out of the loop and we would return true to whoever was asking does this student exist? That's a fair amount of code. The declarative way of solving that same problem would be to ask the students, which is the collection here the list of students, ask the students if it contains Edward. And in this case it would be true. So if we go take a look at how that worked, the code, rather than having to write it every time you want to play that game, does this student exist or not, is contained within the student type equals method. So earlier we saw the natural order of a student was to compare myself to another student by last name. Well, here we've added an equals in a hash code which is what gets called upon when collections not contains is invoked. So let's come back and look at that one more time. When the collection contains method is invoked, the student equals method is what will be invoked. So the first thing it's going to do is say is the other type of object the same type as I am? In other words, I wanna make sure that a student is being compared to another student. And at that point I can say, does my ID equal this other student ID? So it's a much cleaner approach. And as you can see if, if that's the question that someone wants to be able to ask you, it's much cleaner just to say, 'Students does you contains Edward?' Much simpler to do that than to write all of this code. So let's take a look at another example here and that is an imperative sort using a comparator which we've seen this, I believe, collection sort students and sort them this way. So if we go look at students by birth date comparator, well there it is, we're gonna end up sorting the students, given two students at a time by comparing their dates of birth. So they'll all be sorted now chronologically based upon their date of birth. And the declarative flavor of this would not require us to write this, it would not require that. The declarative flavor of that sort is what we're going to be seeing in the next lesson. Thanks for watching. The next lesson will be Lambda and Functional Interfaces.