Artwork

Вміст надано Trevor Page. Весь вміст подкастів, включаючи епізоди, графіку та описи подкастів, завантажується та надається безпосередньо компанією Trevor Page або його партнером по платформі подкастів. Якщо ви вважаєте, що хтось використовує ваш захищений авторським правом твір без вашого дозволу, ви можете виконати процедуру, описану тут https://uk.player.fm/legal.
Player FM - додаток Podcast
Переходьте в офлайн за допомогою програми Player FM !

EP55 – How to Sort with Streams in Java

37:52
 
Поширити
 

Fetch error

Hmmm there seems to be a problem fetching this series right now. Last successful fetch was on March 28, 2024 21:09 (27d ago)

What now? This series will be checked again in the next day. If you believe it should be working, please verify the publisher's feed link below is valid and includes actual episode links. You can contact support to request the feed be immediately fetched.

Manage episode 318454270 series 2398153
Вміст надано Trevor Page. Весь вміст подкастів, включаючи епізоди, графіку та описи подкастів, завантажується та надається безпосередньо компанією Trevor Page або його партнером по платформі подкастів. Якщо ви вважаєте, що хтось використовує ваш захищений авторським правом твір без вашого дозволу, ви можете виконати процедуру, описану тут https://uk.player.fm/legal.

GitHub link here: https://github.com/tp02ga/FunWithStreams

In this episode we'll talk about how to sort a stream of objects using the “.sorted()” function.

We'll also talk about the differences between using a stream to sort vs using something like Collections.sort(), which has been available since Java v1.2

Episode Transcript

0:09
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.

0:28
All right, ladies and gentlemen, welcome to this next episode of the podcast. It has hit episode number 55. Now, always a pleasure to have you in well in your earbuds and me sitting in front of this microphone in my office. So yes, always a pleasure. Let's dive into the topic for today, which will be a continuation of the theme that we've been working on, which is streams. In this one, I want to dive into sorting, which is not too crazy. There's not too much going on here with sorting in streams, but it's an important thing to know about. And that there's time. If it doesn't take too much, then we can dive on into the next topic, which you never know. I'll see how it looks once we get there. So as always, this lesson or episode of you will is brought to you by the coders campus boot camp. If you are looking to get a job as a coder, we are constantly improving the boot camp, we are constantly bringing in new talent and churning out really the next generation of great coders. And I couldn't be more proud of the students who are going through the curriculum right now. So to all you students who might be listening to this, because I know you are. If you're still in the boot camp, keep keep on truckin. I know, it's tough, I know it's hard. If you have come out the other end, congratulations. And I look forward to seeing you in your future career. So if you're interested, check it out. coaters campus.com/bootcamp to check out all of the details there. So let's go into streams with respect to sorting. So before we had streams, sorting was done or achieved via one of two means in the world of Java, you can either sort using comparable or a comparator. I never know how to pronounce that word, I like to pronounce the tour at the end. So in the world of streams and sorting, it's much the same. So if you're using comparable comparable is an interface that you can implement yourself if you have access to the other class that you want to be sorting. So if you have control over it, meaning if you have created an object, and you wish to sort those objects, you can implement comparable within your objects class, and implement the compare to method that it forces you to override. In our example, we could have done that, but I'm just doing a comparator instead. Because, well, it's it's you can see all the code in front of us. So it's just a little bit easier to get the point across when use a comparator. But this is really, you know, six of one half dozen, or the other is the expression meaning it doesn't really matter which one that you go with, because it's still sorting, sorting is still sorting. So yeah, and this one, we're gonna be using competitors. And that's just like, you can see the code in front of you. So when you did it, quote, unquote, the old way, meaning before you had streams, how did you accomplish sorting? Well, in this example, I'm going to be having I'm going to have a bunch of user objects, the users will have the common things that users always have username, password, but it's also going to have a, which call it

3:36
a last login date. Meaning that this particular class called user has a property called last login date, which is just a date that represents the last time that that user logged in. Now, we're not going to talk about how to implement that functionality that is outside the scope of this conversation, we're just going to assume that that is already done. And we are just handed the data. So we're just handed a collection of these users that has the data prefilled. Now if you're following along with the code that I am making available, you can check it out. Whereas it coderscampus.com/55, I guess will redirect you to this particular entry, or post or whatever you want to call it. And I will have a repo GitHub repo there, where you can check out the code that we're talking about. In any case, if you're following along with the code, then great. If you're not then no worries, I'll do my best as I always try to do to explain it. But yeah, we have a user and we will have or rather a collection of users and the users will have the data pre populated so the code that I will present you with. I just wrote some code to generate users, so it just will randomly generate users with a random username and a random password and random dates. That represent the last time that they've logged in. Basically, I just look at what today is, when you're writing the code, it looks at what today is, that's the maximum day that you can, you know, randomly generate. And the minimum day is like 90 days ago. So no matter when you run this code, whether it's you know, today when I'm recording this episode, or you know, sometime in the future, it should always work. Cool. So it'll generate dates. For last logins, it'll generate usernames and passwords and everything, and it'll generate a list of users. And how do we then go about, you know, accomplishing our sort? And how are we sorting? So for these ones, I want to sort the users by the last login date, so I want to see a list of the ones who, you know, just a list of the sorted users by when they last logged in. But I also want to filter out any users that haven't logged in, you know, in the last 30 days, or prior to 30 days ago, I should say. So what that means is anyone who's logged in 31 days, or are further out in the past, I just don't want to see them. Only the users that I want to see recently who've logged in, those are the ones I want to see. And I want to see them in the sorted list. Okay. Again, why? I don't know, I just sort of picked out of thin air. That's, you know, who knows, maybe there's a business requirement somewhere that says I want to see a sorted list of the most recently logged in users? I don't know, maybe that's useful to someone. So that's what we're going for here. But how do we accomplish it? Well, without streams, again, it's going to be more verbose, right? Without streams, you're first going to have to filter the list based on the getting rid of the people who have logged in more than 30 days ago. So I have some code there to filter lists. We've talked about filtering before. Without streams, you just have to iterate through them, you need to create a new collection. While you iterate through the existing collection, you will insert into the new collection, all of the entries that meet your filtering criteria. Okay, that's essentially how you get it done. I don't want to go into that we've already talked about that concept before. So we will filter our list create a new one, a new filtered list with just the ones who have logged in no more than 30 days ago. So now we have our filtered list. And how do we sort a list? Well, you can use collections dot sort, this is something that was has been available for a little while I forget when it was created since 1.2. So Java 1.2. So for quite a while you've been able to do collections dot sort. And collections dot sort takes an input of a list. So you pass in the list, but then it's not going to know how to sort that list. Because it's it's a, it's a custom type, right, we have created the user class, the user type, so it's not going to know how to sort it. So you need to tell it how to sort it either using comparable that we talked about before, or using comparator. So we can instantiate a new comparator, which is the way I'm going here, instantiate instantiate a new comparator, which forces you to override the Compare method. And then you can put the code in to compare the log in the last logon dates for all the users. Okay, I don't really want to go into all the code there that's needed. But suffice it to say, it's, I don't know, a few lines of code, right. So in total, we're talking about what 1234567 ish lines of code here to accomplish everything that I've talked about. And then you can output you know, your list your filtered list of users. So that's sort of the old way of doing it. Now, there's not there's not that there is anything wrong with that. It's just a little bit verbose. You just have to spell it all out. And it's not very sexy, it's not very, you know, it's just not easy to read, so to speak, right? That's, we've talked about this before, streams, makes code much easier to read, in my opinion. And in the opinion of like all the developers who've ever used streams. So yeah, that's how you accomplish that task. Now one side effect that happens with the collections dot sort method, which is the old way of sorting. Again, I keep I say old way, only to say that this is not using streams. So this is the non stream way to sort you can leverage collections dot sort. There are certainly other ways to sort this is just one of them. The side effects using collections dot sort is it will mutate the collection, mutate the list that you are giving to the collections dot sort function. So it will actually mutate that list, right? So this is a this is called side effects. This is where, if you're not aware that this is happening, it can cause some bugs, right, you can accidentally change a set of data that you didn't mean to change. Or you can change it from the outside, right. So if you change it inside a method, it has also been changed outside of the method or the file. function. So there's just, you know, there's that side effect that you need to be aware of. Now, if you're aware of it, then it's fine. Because you know, okay, cool. I know that when I do collections dot sort is going to mutate the list that I'm passing in. And am I okay with that? Am I okay with it, mutating that list, if I am, if I am the no problem, if I'm not, I should create a copy of that list first, okay. So that's just that little extra bit of knowledge that you need to have knowledge, you need to have that knowledge in order to move forward and avoid any bugs, right? For those of you in the know, no big deal. So that's more or less the only thing other than it being verbose that that is sort of different between, quote, unquote, sorting the old way. So now, if you talk about sorting the new way, which is leveraging streams, again, it's less verbose. So with the streams here with the new streams, what we can do is, you can take your collection that you're starting with, which is I just called it users is the name of the variable, which is the list of whatever number of users that's, you know, randomly generated. So users dot stream, that's how we kick things off. Dot stream is how we kick off all the streams. Now we want to filter right, so we can do dot filter. And you can do that.

11:16
What's called the predicate I think is the word it's been a little while since I've looked into all these Yes, predicate is what you pass in. So the predicate uses returns a true or false, it returns a Boolean, based on the you know, function that you give it. And function that we're doing is comparing to see hey, when is the last logon date more than 30 days ago. If it is, then you return false. And if it's not meaning, if it's more recent than that, if it's within the last 30 days, you can return true, again, how to do that doesn't matter. Just know that it's filtering based on that if you want to check it out, check it out in the code, coderscampus.com/55. So cool. Now in the again, the old way to filter, there was a bunch of steps there that was needed. And the new way, we're just, it's one line of code dot filter, you pass in the way you filter, and then you move on to the next chained method. In other words, we just put another dot after the filter, so say dot, then you can do something else. This one you can do dot sorted. Okay, so this is the this is the, you know, comparable, I shouldn't use the word comparable. This is the equivalent function to collections dot sort. Okay, so you can say dot sorted. So on a stream, on any stream of objects, you can say dot sorted. And what dot sorted takes as an input to this function takes as an input is a comparator. So allows you to pass in a comparator. And since we're using fancy schmancy, lambda syntax, we can use the lambda syntax for competitors, which is just you, you you know, put your on the left hand side of the arrow function, you have your two inputs, because it wants to objects, right? Object one, object two, or user one, user two, whatever you want to call it. Okay, this is what it's gonna be using to compare. So as it goes through the list, to compare all the elements and sort them, that's what it takes it constantly, you know, populates those two inputs, the object one, object two, or user one, user two, whatever you want to call it, that's the left hand side of the lambda arrow expression thingy for the dot sorted function. On the right hand side of the arrow, is the actual comparison. And again, we had to do this above, we had I say, above, because the code the old code is above, we had to do this the old way as well. So this is not new codes, not something different, is just more concise. So same comparison, we compare last login for the object one to compare to last login for object two, and then you close the parentheses. So that's sort of the sorted function that you pass in. So first you stream, then you filter, then you're sort, and then you collect, stream Filter, Sort collect, dot, dot, dot, dot, right, dot stream dot filter, dot sort dot collect. That is how the sort of more functional programming syntax boils down. It's very readable. Okay, I'm streaming users, that I'm filtering them somehow. And then I'm sorting the ones that have been filtered somehow. And I'm collecting them to a list to a new list. So dot collect and redo collectors.to list. That's how we again, we've talked about that before. So you assign this to a new list of users, right and call it filtered users or whatever you like. So the difference here now now we're done. That's it. Right? You had those four functions that you call dot stream dot filter, dot sorted dot collect. We're done. And the difference here is again, not not a earth shattering difference and you know, we're talking But four lines of code instead of seven now, so it's, it's not as verbose, but only by three lines of code. But it's much more readable, in my opinion, right, the other one will take you longer to understand. But this one's a lot more readable. And there's no side effect, meaning we are not mutating the input write users. When I say users dot stream, and the dot filter dot sorted collect users is that original list of 10 users? It we are not mutating that original list because streams, leveraging functional coding, the functional coding paradigm, is that it you know, it doesn't mutate stuff, everything is immutable, everything is final, right? Meaning you can't, you know, mess around with it. So it's just part of the functional programming, you know,

15:51
I don't know handbook or whatever you want to call it, they try to be as immutable as possible. So what that means is, when we are returning, we're collecting everything to a new list, we call it filtered, or I called it filtered users is the new list that we return, which means that we did not change the original list of users. So that's, you know, it take that for, you know, if you if you wanted to modify the original list of users, you can you can just assign it back to users. Least I think you can. Let me try to do that right now in my in my code and see if it gives me an error anything. Users go live coding on the podcast, ladies and gentlemen, let me just play this out and see does it break anything? Well, sort of it? Yeah. Cuz I mutated the original list. The second test was based but anyway, fundamentally speaking, no, I didn't break anything. So it's, you're able to do that. So the the, the benefit here, if you will, of using the new way using streams, to sort is that you have the choice. You can choose to not mutate. Or you can choose to mutate depending on which is what your preference, which one is your preference. There you go. I guess that's how you say it. Yeah, so you can make the choice yourself, you can choose to mutate or not, whatever tickles your fancy. So that's it for really for sorting right now. There could be other I don't know if there's any other sorting methods, I guess the only other sorted method is you can do just dot sorted without a comparator. If the object or the objects the class, that you're trying to sort the class that you're streaming, or gets the objects that you're streaming, if that implements Comparable, then you're good, then you don't have to pass in a comparator, right, a comparator. So if you had if you were streaming and sorting a list of like strings, well, strings, by default already have a way to sort themselves, it just sorts alphabetically, right? If you were streaming integers, or Long's or whatever, those already know how to sort themselves, right? Java has the people who program Java have already put that code in place to tell it how to sort itself. So you can just do dot sorted. And then you don't even need to pass in a comparator. But again, that's the same thing that you can do with the old way as well. You can do collections dot sort, and pass in a collection of strings, or a collection of integers, or a collection of Long's and it'll just sort itself, you don't have to pass in the comparator. So really, again, we have the same thing going on here. But it's I guess, good to know that you don't have to use a comparator. Like we did in this example, if you don't want to, if the objects that you are streaming, implement comparable, okay, so like I said, not a whole lot of, of fanciness going on here. Other than, like I said, that little bit of a note on mutability, and how with functional programming, it's more readable and immutable. It's just a little bit safer and a little bit more readable. So once you understand how to do this stuff, it just tends to be the go to way that I code myself, personally speaking.

19:00
I don't want to say that you have to do it that way. But it's just I just find once I got comfortable with it, which for me didn't take too too long. It was definitely a learning curve, and hence why I'm talking about here on the podcast. But once you learn how to do this stuff, it just becomes a little bit more second nature and a lot more nice to work with, in my opinion. So that is me on my quote unquote, high quote unquote, high horse that is me on my high horse saying, Hey, you guys should use streams if you're not already using them. And yeah, I mean, I could now we could go on and move on to another topic, but I guess, you know, I'm over already 20 minutes. And of course, I'm long winded. How do we not see that coming? I don't want this to turn into like a 45 minute podcast, but there was some code in there that I did. In my example. Again, if you go to coderscampus.com/55. And you go to the GitHub repository that I will link in the notes there. You'll see that I leveraged something called an int stream To do some loops, looping type code, and yeah, I want to talk about in streams and into meaning it streams. And how it is a does it extend the stream, I forget if it extends a stream or not extends base stream, which was that extends auto closable. I guess this is not extended stream, auto closable does not extends interesting, I thought I extended the stream anyway, an int stream is just a different type of stream that unlocks some new or different I should say functionalities. Maybe I'll I'll touch on that in the next episode of this podcast. We'll try get the next episode out really quickly now, because I'm already talking about int streams. But in streams are really fun. Because there's a lot of cool stuff that you can do with it, you know, you can use it to replace a typical for loop. And you can even use it to get some really cool statistics on any data set that you have. In this Yeah, it unlocks some pretty powerful stuff there. So we'll talk about that one in the next lesson. Again, I'll try to get that out ASAP. And hey, if you haven't already checked it out, again, I'm sure you have heard about it and but may not have checked it out. coderscampus.com/bootcamp, right? If your goal is to get a job as a coder, if you want to get paid, you know really a lot of money for doing something that if you're listening to these podcasts and enjoying them, then you get paid a lot of money to do something that's fun. Fun once you you get the hang of it, right? Always the learning curve is not that fun unless you figure it out. And then you have a lot of fun. Once you figure something out and make a breakthrough, then you feel great. But then it's just on to the next, you know thing to struggle on and have to make a breakthrough on then you get back into the hole. Oh my god, I'm not good enough for this. I'm not, you know, smart enough. I'm not this. I'm not that. Anyway, we've talked about this whole mindset thing around coding before on the podcast and how it is, in my opinion, one of the number one things that stops people from achieving their goal, right, they think they're not good enough. And really, every single coder thinks that they're not good enough, every single one, I have not met, I don't think I've ever met a coder who hasn't, at some point, hit the struggles and said like, Ooh, I don't know, like, I really want to do this. But this is really testing my resolve, right? Even Even people in my in my boot camp who I would have, I would have bet that they like one person in particular comes to mind where I would have bet that they would have sailed through the the podcast sale to the boot camp with very minimal hiccups. And then it turned out that whatever was halfway through or three quarters of the way through this particular individual really started to struggle, and then start to fall behind and then lose faith in their ability and start to, you know, stop showing up for the calls. And it was like oh, man, like I didn't. It's amazing how hard this is. That's the that's the message I want to get across. So the people who make it across the finish line are the ones who seek mentorship. I know I'm a broken record. I've said this before you've heard this before from me. But seeking mentorship and always asking questions and always asking for help is the way to achieve the goal. Okay, it is I have not yet met a student who has reached out and asked for help through the mentorship that they get in the boot camp throughout the entire thing. Who has not made it out the other end? Okay, not yet. Um, there might be one but I'm tired. I'm saying 99% of the time if you are someone who just keeps going, keeps asking questions, keeps showing up, keeps asking for help and keep getting that help from something like a bootcamp you are going to make it okay the job market is so hot right now, especially now in I'm recording this in 2022.

23:55
And again, this this this statement has never changed. Okay, my statement of the job market is so hot right now hasn't changed since I graduated university in 2006. Seven. Okay, the job market is ridiculous. Okay, but the job market for senior level programmers is ridiculous. Okay, the job market for entry level is still good. But it's not as good as senior level because students it's there's so many people who try to be qualified as and who who advertise themselves as qualified to be a junior level, right an entry level coder, but so many of them are not qualified. Right. And because of that, employers don't see the value in junior level as much as they do in senior level, but I'm shifting that on its head. I'm saying there's far far more value in a well educated entry level programmer than a senior senior level programmer, in my opinion. Okay, if someone has gone through a program like this boot camp on top About coderscampus.com/bootcamp, I am happy to hire my own boot camp students. Okay, I'm happy to hire my own boot camp students who show me that resolve that I was talking about before that drive that always showing up that always asking questions that you can't teach, I cannot teach you to take action, I cannot teach you to reach out and ask for help and ask questions I cannot teach you to not give up. That is something that you have to be good at yourself, okay, you have to have the resolve, you have to have the drive and the desire more than just the motivation to go forward. Okay, that I can't teach. But if you have that skill set, okay, if you've earned it, or learned it, or whatever, that kind of stuff. The rest is, is easy for me, I can teach you how to code, right? This is that that part's simple. Okay, that's just time. That's all that is. And once you get through the other end, I will hire the heck out of you if you know. So anyway, long story short. In my opinion, the coding boot camp is the solution. It is the path to employment, okay, to starting a new career, there are plenty of entry level jobs, for coders who are good enough, and you will be good enough if you go through the boot camp. And once you're beyond that, once you've had a year or two of experience, the world becomes your oyster. I know I've said this before, but it is so so true. as true today as it has ever been. There are just so many people, so many recruiters banging down my door banging down the doors of all senior programmers out there desperately trying to find people to, to fill the holes in the hiring process of other companies. So so many companies are looking for programmers who are qualified and they just can't find them fast enough. Okay, as myself as a business owner, as an employer, myself, I have felt this pain before I have felt the pain of Oh, no, I need more people. And I don't think I can find them. Or it's very, very difficult to find these people. Okay, I felt that pain before, not with programmers specifically with a different role. But now Now I understand the pain of Oh, no, like, where do I go to get these people? If I can't get these people? What am I going to do, I'm going to be in trouble. And that is the exact feeling that these employers have with respect to hiring programmers. So that's why I've taken it on myself my mission to train people on how to become the next generation of great coders. So we can fill those gaps, help those employers and help you at the same time. Okay, the university education and the university system, at least in North America, from what I've seen, falls very short of being able to fulfill this promise of allowing you to be job ready, and allowing you to go into one of these roles and understand what's going on. Okay, being able to hit the ground running. Okay? I haven't I just It still hasn't changed. Every every student I speak to every university student I speak to, they all repeat the same thing. I don't feel like I'm ready. Okay, and they're not I know, because I was one of them before. With a boot camp students, I just had a student last week, who's gone through the boot camp who is is pretty much graduate at this point. They're just waiting for their final review on their on their final project. They got a practice coding assignment that they needed to do. So they applied to a job. And they were given a practice coding assignment to fill out. And this student started to work on the practice coding assignment. They read through the requirements for the coding assignment, and they said, Oh, this looks exactly like assignment, I think nine or something in the curriculum in my boot camp. They're like, Oh, it's it's just assignment or assignment. 10, I think it was, they're like, Oh, this is just assignment 10 with different names, right? Different names, meaning different, different domain objects anyway.

28:57
But it was a, it was a simple assignment of, you know, you need to be able to do the CRUD operations on calling an API. And they were like, Oh, I've done that before. And they wrote able to code 95% of the project. And then they hit the last 5%, where it's at, okay, now, you did do that these XYZ things. And they were like, Ah, I'm, I haven't done that before. And that's always going to happen, right? I can only you can only know so much until there's that last 5% that you need to look up yourself. So guess what, they had the skill to be able to first reach out and ask for help. And I said, good question. Go google it. Right. And then they went in the Google that. And they're like, Oh, I think this is the way to do it. And I said, Yes, that's the way to do it. So this, you're learning. I'm teaching you guys on the podcast, as well as the bootcamp how to prepare for the real world. And I just see this every single time where students are like, Oh, they get their first you know, project on the job, or they get their first practice assignment. And they're like, Oh, that was assignment three here. That was assignment. 10. That was assignment six. So that was assignment and I say, Wow, imagine that shocking. Like, I keep saying a lot. I base my assignments off of the real world, but it doesn't really sink in. It sounds like marketing. But when you see it happening in the in in front of you when you are living the promise that the marketing talks about, you go, Oh, that's really helpful. Thank you, Trevor. And I'm like, okay, good. You're welcome. So anyway, I'm talking way too long than I meant to about this, but I just wanted to share some stories. And if you are someone who suffers from the I'm not good enough syndrome, and the I don't think I could ever make it syndrome, and everyone else can do it, but maybe not me, or I'm gonna be able to deserve this. I don't know, whatever you're struggling with. I've heard it all before. I've seen it all before. What it comes down to is the drive Do you want this or not? Okay, and do you want this soon? Do you want this in the next six to maybe nine months? Okay, or do you want to wait 18 or 24 or 36 months, I have, I cannot count the number of posts, I have seen on StackOverflow or not Stack Overflow on like Reddit, of people saying, oh my god, I got my first job, Yay, I'm a programmer. This is you know, I'm a self taught and I knew I can do it on my own. And that's great. I'm very, very happy for those people. I, I'm thrilled that they made it out. That's the goal. That's the dream. But then you read their story. And it's like, yeah, I started learning how to code, you know, 17 years ago, and it's like, Oh, my God, that's an exaggeration. But maybe they said, you know, three years ago, two years ago, and it's like, well, if you if you're okay, with waiting two years, great. But if you're in a situation where you want this, now, you want the salary, now you want the the outcome now, and you're ready to go. Now, boot camps are cheaper.

31:45
Okay, learning on your own might be free. But the opportunity cost that you give up, learning on your own and stumbling for two or three or four years, that has immense cost. So if you are ready to go now, if you want this stuff now, if you are more than motivated. Now, if you are driven. Now, if you will stop at nothing to unlock the career stability and an income, you know, now, if you want to, like, boot camps are the way to go. Okay, there's nothing I've seen that goes faster than boot camps. So I'm sorry, this is I did not mean to speak this long about this subject. But I just want to get that point across. So if you're still listening, and if this is actually, if you're listening on purpose, meaning if you're just doing the dishes, and your hands are wet, and you can't turn off the phone and skip what I'm saying, I'm very sorry, I will stop talking very, very soon. But if you're purposefully listening to this, if you're making the choice to listen to this, and you are considering it, and if this is striking a nerve with you, and making you feel like maybe I should check this thing out. I know it costs money, okay, it does cost money. But we're trying to structure it in such a way that you pay as absolutely the least amount of money as you possibly can to just cover the cost of the boot camp. Okay, just just my I don't take any profit at all, from this arrangement. And I'm saying this, I probably shouldn't be saying this out loud, because I don't know what this offer is going to be forever from now. But currently, as it stands right now, we're trying to make it so you can pay just the cost, meaning you only pay for the cost of the support that you're going to receive in the bootcamp and that's it. And the rest is could be potentially put into something called an income share agreement, where you don't pay that amount until you get a job as a coder making like $60,000 a year or more something right? Now, don't quote me on that I need to, I'm still ironing out the details. And I'm gonna get yelled at by my team for saying this out loud. But maybe they don't know they don't listen to the podcast. So I'm trying to structure it so that you pay the least amount of money as possible just to get the in, get in, get the education, and then you don't pay a cent until I get you out the other end and I help you to get that job. Once you have a job as a programmer, then you pay the rest of the balance. Right, that's sort of the deal that we're trying to structure. So that way I am I've always been motivated and incentivized to get jobs for my students that has never changed. But now I'm putting my money where my mouth is even more so by saying, Look, if you don't get a job as a coder, if you're if you don't get a job making less than 60k, then you don't pay back anything. And that's okay. There's no legal ramifications, that means I have failed. Okay, so long as you graduate, I should say that is the current stipulation, you need to graduate which means you need to do the work you need to show up you need to attend, you know, and do the assignments and follow my instructions, right if you choose to not follow my instructions and choose to not do any work and not show up and drop out, well, I can't help you. I'm not going to guarantee you a job and you're still gonna have to pay a penalty for that. Because that's you tapping out not me. This can be done as long as you're ready. As long as you're driven and you're willing to show up. I can I can extend that offer to you now you should also stay. Because I'm saying this out loud. The stipulation is for certain countries, for there are certain countries where even if you're the top developer, you're the best developer in on the planet, you're still not going to make $60,000 a year. That's just the way you know, global economics work. So this offer is limited to certain countries where, you know, your entry level salary is on average for a programmer. $60,000. Right. Yeah. So in other words, North America, some countries in Europe and whatnot. That's what this applies to. So I should make that that distinction now. But yeah, that's, that tends to be the majority of the people listening to the podcast, I'm very sorry, if you live in Pakistan, or India or something, and you're looking to get that kind of deal that education, I'm sorry, but it's just too expensive. And there's nothing I can do to solve global economic issues like that. Anyway, okay. I will stop talking. So coderscampus.com/bootcamp. If you are interested, now is the time to reach out. As soon as I release this podcast, reach out. You know, you go to the website, coders campus.com/boot camp and click to talk to us or whatever apply, send us a message, whatever, however you want to get in touch and say, Hey, I heard Trevor talking on the podcast about this offer where I only pay, you know, the cost of the bootcamp. I don't pay any anything else until I graduate and get a job and make $60,000 a year I want that offer. Right. So if that's you if that sounds good. Go now, coderscampus.com/bootcamp. And you know, fill out an application form. And make sure you have at least you know, 10 to 20 hours a week free. Because if you have less than 10 hours a week free, it's just gonna take too long. And then you might as well just learn on your own. Cool. Cool, I will stop talking. Thank you very much. Until next time again, I've promised you we will be learning about it streams i NT streams in the next lesson. So look forward to seeing you there. Take care of yourself as always, Happy learning. And bye for now.

37:07
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

The post EP55 – How to Sort with Streams in Java appeared first on Coders Campus.

  continue reading

74 епізодів

Artwork
iconПоширити
 

Fetch error

Hmmm there seems to be a problem fetching this series right now. Last successful fetch was on March 28, 2024 21:09 (27d ago)

What now? This series will be checked again in the next day. If you believe it should be working, please verify the publisher's feed link below is valid and includes actual episode links. You can contact support to request the feed be immediately fetched.

Manage episode 318454270 series 2398153
Вміст надано Trevor Page. Весь вміст подкастів, включаючи епізоди, графіку та описи подкастів, завантажується та надається безпосередньо компанією Trevor Page або його партнером по платформі подкастів. Якщо ви вважаєте, що хтось використовує ваш захищений авторським правом твір без вашого дозволу, ви можете виконати процедуру, описану тут https://uk.player.fm/legal.

GitHub link here: https://github.com/tp02ga/FunWithStreams

In this episode we'll talk about how to sort a stream of objects using the “.sorted()” function.

We'll also talk about the differences between using a stream to sort vs using something like Collections.sort(), which has been available since Java v1.2

Episode Transcript

0:09
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.

0:28
All right, ladies and gentlemen, welcome to this next episode of the podcast. It has hit episode number 55. Now, always a pleasure to have you in well in your earbuds and me sitting in front of this microphone in my office. So yes, always a pleasure. Let's dive into the topic for today, which will be a continuation of the theme that we've been working on, which is streams. In this one, I want to dive into sorting, which is not too crazy. There's not too much going on here with sorting in streams, but it's an important thing to know about. And that there's time. If it doesn't take too much, then we can dive on into the next topic, which you never know. I'll see how it looks once we get there. So as always, this lesson or episode of you will is brought to you by the coders campus boot camp. If you are looking to get a job as a coder, we are constantly improving the boot camp, we are constantly bringing in new talent and churning out really the next generation of great coders. And I couldn't be more proud of the students who are going through the curriculum right now. So to all you students who might be listening to this, because I know you are. If you're still in the boot camp, keep keep on truckin. I know, it's tough, I know it's hard. If you have come out the other end, congratulations. And I look forward to seeing you in your future career. So if you're interested, check it out. coaters campus.com/bootcamp to check out all of the details there. So let's go into streams with respect to sorting. So before we had streams, sorting was done or achieved via one of two means in the world of Java, you can either sort using comparable or a comparator. I never know how to pronounce that word, I like to pronounce the tour at the end. So in the world of streams and sorting, it's much the same. So if you're using comparable comparable is an interface that you can implement yourself if you have access to the other class that you want to be sorting. So if you have control over it, meaning if you have created an object, and you wish to sort those objects, you can implement comparable within your objects class, and implement the compare to method that it forces you to override. In our example, we could have done that, but I'm just doing a comparator instead. Because, well, it's it's you can see all the code in front of us. So it's just a little bit easier to get the point across when use a comparator. But this is really, you know, six of one half dozen, or the other is the expression meaning it doesn't really matter which one that you go with, because it's still sorting, sorting is still sorting. So yeah, and this one, we're gonna be using competitors. And that's just like, you can see the code in front of you. So when you did it, quote, unquote, the old way, meaning before you had streams, how did you accomplish sorting? Well, in this example, I'm going to be having I'm going to have a bunch of user objects, the users will have the common things that users always have username, password, but it's also going to have a, which call it

3:36
a last login date. Meaning that this particular class called user has a property called last login date, which is just a date that represents the last time that that user logged in. Now, we're not going to talk about how to implement that functionality that is outside the scope of this conversation, we're just going to assume that that is already done. And we are just handed the data. So we're just handed a collection of these users that has the data prefilled. Now if you're following along with the code that I am making available, you can check it out. Whereas it coderscampus.com/55, I guess will redirect you to this particular entry, or post or whatever you want to call it. And I will have a repo GitHub repo there, where you can check out the code that we're talking about. In any case, if you're following along with the code, then great. If you're not then no worries, I'll do my best as I always try to do to explain it. But yeah, we have a user and we will have or rather a collection of users and the users will have the data pre populated so the code that I will present you with. I just wrote some code to generate users, so it just will randomly generate users with a random username and a random password and random dates. That represent the last time that they've logged in. Basically, I just look at what today is, when you're writing the code, it looks at what today is, that's the maximum day that you can, you know, randomly generate. And the minimum day is like 90 days ago. So no matter when you run this code, whether it's you know, today when I'm recording this episode, or you know, sometime in the future, it should always work. Cool. So it'll generate dates. For last logins, it'll generate usernames and passwords and everything, and it'll generate a list of users. And how do we then go about, you know, accomplishing our sort? And how are we sorting? So for these ones, I want to sort the users by the last login date, so I want to see a list of the ones who, you know, just a list of the sorted users by when they last logged in. But I also want to filter out any users that haven't logged in, you know, in the last 30 days, or prior to 30 days ago, I should say. So what that means is anyone who's logged in 31 days, or are further out in the past, I just don't want to see them. Only the users that I want to see recently who've logged in, those are the ones I want to see. And I want to see them in the sorted list. Okay. Again, why? I don't know, I just sort of picked out of thin air. That's, you know, who knows, maybe there's a business requirement somewhere that says I want to see a sorted list of the most recently logged in users? I don't know, maybe that's useful to someone. So that's what we're going for here. But how do we accomplish it? Well, without streams, again, it's going to be more verbose, right? Without streams, you're first going to have to filter the list based on the getting rid of the people who have logged in more than 30 days ago. So I have some code there to filter lists. We've talked about filtering before. Without streams, you just have to iterate through them, you need to create a new collection. While you iterate through the existing collection, you will insert into the new collection, all of the entries that meet your filtering criteria. Okay, that's essentially how you get it done. I don't want to go into that we've already talked about that concept before. So we will filter our list create a new one, a new filtered list with just the ones who have logged in no more than 30 days ago. So now we have our filtered list. And how do we sort a list? Well, you can use collections dot sort, this is something that was has been available for a little while I forget when it was created since 1.2. So Java 1.2. So for quite a while you've been able to do collections dot sort. And collections dot sort takes an input of a list. So you pass in the list, but then it's not going to know how to sort that list. Because it's it's a, it's a custom type, right, we have created the user class, the user type, so it's not going to know how to sort it. So you need to tell it how to sort it either using comparable that we talked about before, or using comparator. So we can instantiate a new comparator, which is the way I'm going here, instantiate instantiate a new comparator, which forces you to override the Compare method. And then you can put the code in to compare the log in the last logon dates for all the users. Okay, I don't really want to go into all the code there that's needed. But suffice it to say, it's, I don't know, a few lines of code, right. So in total, we're talking about what 1234567 ish lines of code here to accomplish everything that I've talked about. And then you can output you know, your list your filtered list of users. So that's sort of the old way of doing it. Now, there's not there's not that there is anything wrong with that. It's just a little bit verbose. You just have to spell it all out. And it's not very sexy, it's not very, you know, it's just not easy to read, so to speak, right? That's, we've talked about this before, streams, makes code much easier to read, in my opinion. And in the opinion of like all the developers who've ever used streams. So yeah, that's how you accomplish that task. Now one side effect that happens with the collections dot sort method, which is the old way of sorting. Again, I keep I say old way, only to say that this is not using streams. So this is the non stream way to sort you can leverage collections dot sort. There are certainly other ways to sort this is just one of them. The side effects using collections dot sort is it will mutate the collection, mutate the list that you are giving to the collections dot sort function. So it will actually mutate that list, right? So this is a this is called side effects. This is where, if you're not aware that this is happening, it can cause some bugs, right, you can accidentally change a set of data that you didn't mean to change. Or you can change it from the outside, right. So if you change it inside a method, it has also been changed outside of the method or the file. function. So there's just, you know, there's that side effect that you need to be aware of. Now, if you're aware of it, then it's fine. Because you know, okay, cool. I know that when I do collections dot sort is going to mutate the list that I'm passing in. And am I okay with that? Am I okay with it, mutating that list, if I am, if I am the no problem, if I'm not, I should create a copy of that list first, okay. So that's just that little extra bit of knowledge that you need to have knowledge, you need to have that knowledge in order to move forward and avoid any bugs, right? For those of you in the know, no big deal. So that's more or less the only thing other than it being verbose that that is sort of different between, quote, unquote, sorting the old way. So now, if you talk about sorting the new way, which is leveraging streams, again, it's less verbose. So with the streams here with the new streams, what we can do is, you can take your collection that you're starting with, which is I just called it users is the name of the variable, which is the list of whatever number of users that's, you know, randomly generated. So users dot stream, that's how we kick things off. Dot stream is how we kick off all the streams. Now we want to filter right, so we can do dot filter. And you can do that.

11:16
What's called the predicate I think is the word it's been a little while since I've looked into all these Yes, predicate is what you pass in. So the predicate uses returns a true or false, it returns a Boolean, based on the you know, function that you give it. And function that we're doing is comparing to see hey, when is the last logon date more than 30 days ago. If it is, then you return false. And if it's not meaning, if it's more recent than that, if it's within the last 30 days, you can return true, again, how to do that doesn't matter. Just know that it's filtering based on that if you want to check it out, check it out in the code, coderscampus.com/55. So cool. Now in the again, the old way to filter, there was a bunch of steps there that was needed. And the new way, we're just, it's one line of code dot filter, you pass in the way you filter, and then you move on to the next chained method. In other words, we just put another dot after the filter, so say dot, then you can do something else. This one you can do dot sorted. Okay, so this is the this is the, you know, comparable, I shouldn't use the word comparable. This is the equivalent function to collections dot sort. Okay, so you can say dot sorted. So on a stream, on any stream of objects, you can say dot sorted. And what dot sorted takes as an input to this function takes as an input is a comparator. So allows you to pass in a comparator. And since we're using fancy schmancy, lambda syntax, we can use the lambda syntax for competitors, which is just you, you you know, put your on the left hand side of the arrow function, you have your two inputs, because it wants to objects, right? Object one, object two, or user one, user two, whatever you want to call it. Okay, this is what it's gonna be using to compare. So as it goes through the list, to compare all the elements and sort them, that's what it takes it constantly, you know, populates those two inputs, the object one, object two, or user one, user two, whatever you want to call it, that's the left hand side of the lambda arrow expression thingy for the dot sorted function. On the right hand side of the arrow, is the actual comparison. And again, we had to do this above, we had I say, above, because the code the old code is above, we had to do this the old way as well. So this is not new codes, not something different, is just more concise. So same comparison, we compare last login for the object one to compare to last login for object two, and then you close the parentheses. So that's sort of the sorted function that you pass in. So first you stream, then you filter, then you're sort, and then you collect, stream Filter, Sort collect, dot, dot, dot, dot, right, dot stream dot filter, dot sort dot collect. That is how the sort of more functional programming syntax boils down. It's very readable. Okay, I'm streaming users, that I'm filtering them somehow. And then I'm sorting the ones that have been filtered somehow. And I'm collecting them to a list to a new list. So dot collect and redo collectors.to list. That's how we again, we've talked about that before. So you assign this to a new list of users, right and call it filtered users or whatever you like. So the difference here now now we're done. That's it. Right? You had those four functions that you call dot stream dot filter, dot sorted dot collect. We're done. And the difference here is again, not not a earth shattering difference and you know, we're talking But four lines of code instead of seven now, so it's, it's not as verbose, but only by three lines of code. But it's much more readable, in my opinion, right, the other one will take you longer to understand. But this one's a lot more readable. And there's no side effect, meaning we are not mutating the input write users. When I say users dot stream, and the dot filter dot sorted collect users is that original list of 10 users? It we are not mutating that original list because streams, leveraging functional coding, the functional coding paradigm, is that it you know, it doesn't mutate stuff, everything is immutable, everything is final, right? Meaning you can't, you know, mess around with it. So it's just part of the functional programming, you know,

15:51
I don't know handbook or whatever you want to call it, they try to be as immutable as possible. So what that means is, when we are returning, we're collecting everything to a new list, we call it filtered, or I called it filtered users is the new list that we return, which means that we did not change the original list of users. So that's, you know, it take that for, you know, if you if you wanted to modify the original list of users, you can you can just assign it back to users. Least I think you can. Let me try to do that right now in my in my code and see if it gives me an error anything. Users go live coding on the podcast, ladies and gentlemen, let me just play this out and see does it break anything? Well, sort of it? Yeah. Cuz I mutated the original list. The second test was based but anyway, fundamentally speaking, no, I didn't break anything. So it's, you're able to do that. So the the, the benefit here, if you will, of using the new way using streams, to sort is that you have the choice. You can choose to not mutate. Or you can choose to mutate depending on which is what your preference, which one is your preference. There you go. I guess that's how you say it. Yeah, so you can make the choice yourself, you can choose to mutate or not, whatever tickles your fancy. So that's it for really for sorting right now. There could be other I don't know if there's any other sorting methods, I guess the only other sorted method is you can do just dot sorted without a comparator. If the object or the objects the class, that you're trying to sort the class that you're streaming, or gets the objects that you're streaming, if that implements Comparable, then you're good, then you don't have to pass in a comparator, right, a comparator. So if you had if you were streaming and sorting a list of like strings, well, strings, by default already have a way to sort themselves, it just sorts alphabetically, right? If you were streaming integers, or Long's or whatever, those already know how to sort themselves, right? Java has the people who program Java have already put that code in place to tell it how to sort itself. So you can just do dot sorted. And then you don't even need to pass in a comparator. But again, that's the same thing that you can do with the old way as well. You can do collections dot sort, and pass in a collection of strings, or a collection of integers, or a collection of Long's and it'll just sort itself, you don't have to pass in the comparator. So really, again, we have the same thing going on here. But it's I guess, good to know that you don't have to use a comparator. Like we did in this example, if you don't want to, if the objects that you are streaming, implement comparable, okay, so like I said, not a whole lot of, of fanciness going on here. Other than, like I said, that little bit of a note on mutability, and how with functional programming, it's more readable and immutable. It's just a little bit safer and a little bit more readable. So once you understand how to do this stuff, it just tends to be the go to way that I code myself, personally speaking.

19:00
I don't want to say that you have to do it that way. But it's just I just find once I got comfortable with it, which for me didn't take too too long. It was definitely a learning curve, and hence why I'm talking about here on the podcast. But once you learn how to do this stuff, it just becomes a little bit more second nature and a lot more nice to work with, in my opinion. So that is me on my quote unquote, high quote unquote, high horse that is me on my high horse saying, Hey, you guys should use streams if you're not already using them. And yeah, I mean, I could now we could go on and move on to another topic, but I guess, you know, I'm over already 20 minutes. And of course, I'm long winded. How do we not see that coming? I don't want this to turn into like a 45 minute podcast, but there was some code in there that I did. In my example. Again, if you go to coderscampus.com/55. And you go to the GitHub repository that I will link in the notes there. You'll see that I leveraged something called an int stream To do some loops, looping type code, and yeah, I want to talk about in streams and into meaning it streams. And how it is a does it extend the stream, I forget if it extends a stream or not extends base stream, which was that extends auto closable. I guess this is not extended stream, auto closable does not extends interesting, I thought I extended the stream anyway, an int stream is just a different type of stream that unlocks some new or different I should say functionalities. Maybe I'll I'll touch on that in the next episode of this podcast. We'll try get the next episode out really quickly now, because I'm already talking about int streams. But in streams are really fun. Because there's a lot of cool stuff that you can do with it, you know, you can use it to replace a typical for loop. And you can even use it to get some really cool statistics on any data set that you have. In this Yeah, it unlocks some pretty powerful stuff there. So we'll talk about that one in the next lesson. Again, I'll try to get that out ASAP. And hey, if you haven't already checked it out, again, I'm sure you have heard about it and but may not have checked it out. coderscampus.com/bootcamp, right? If your goal is to get a job as a coder, if you want to get paid, you know really a lot of money for doing something that if you're listening to these podcasts and enjoying them, then you get paid a lot of money to do something that's fun. Fun once you you get the hang of it, right? Always the learning curve is not that fun unless you figure it out. And then you have a lot of fun. Once you figure something out and make a breakthrough, then you feel great. But then it's just on to the next, you know thing to struggle on and have to make a breakthrough on then you get back into the hole. Oh my god, I'm not good enough for this. I'm not, you know, smart enough. I'm not this. I'm not that. Anyway, we've talked about this whole mindset thing around coding before on the podcast and how it is, in my opinion, one of the number one things that stops people from achieving their goal, right, they think they're not good enough. And really, every single coder thinks that they're not good enough, every single one, I have not met, I don't think I've ever met a coder who hasn't, at some point, hit the struggles and said like, Ooh, I don't know, like, I really want to do this. But this is really testing my resolve, right? Even Even people in my in my boot camp who I would have, I would have bet that they like one person in particular comes to mind where I would have bet that they would have sailed through the the podcast sale to the boot camp with very minimal hiccups. And then it turned out that whatever was halfway through or three quarters of the way through this particular individual really started to struggle, and then start to fall behind and then lose faith in their ability and start to, you know, stop showing up for the calls. And it was like oh, man, like I didn't. It's amazing how hard this is. That's the that's the message I want to get across. So the people who make it across the finish line are the ones who seek mentorship. I know I'm a broken record. I've said this before you've heard this before from me. But seeking mentorship and always asking questions and always asking for help is the way to achieve the goal. Okay, it is I have not yet met a student who has reached out and asked for help through the mentorship that they get in the boot camp throughout the entire thing. Who has not made it out the other end? Okay, not yet. Um, there might be one but I'm tired. I'm saying 99% of the time if you are someone who just keeps going, keeps asking questions, keeps showing up, keeps asking for help and keep getting that help from something like a bootcamp you are going to make it okay the job market is so hot right now, especially now in I'm recording this in 2022.

23:55
And again, this this this statement has never changed. Okay, my statement of the job market is so hot right now hasn't changed since I graduated university in 2006. Seven. Okay, the job market is ridiculous. Okay, but the job market for senior level programmers is ridiculous. Okay, the job market for entry level is still good. But it's not as good as senior level because students it's there's so many people who try to be qualified as and who who advertise themselves as qualified to be a junior level, right an entry level coder, but so many of them are not qualified. Right. And because of that, employers don't see the value in junior level as much as they do in senior level, but I'm shifting that on its head. I'm saying there's far far more value in a well educated entry level programmer than a senior senior level programmer, in my opinion. Okay, if someone has gone through a program like this boot camp on top About coderscampus.com/bootcamp, I am happy to hire my own boot camp students. Okay, I'm happy to hire my own boot camp students who show me that resolve that I was talking about before that drive that always showing up that always asking questions that you can't teach, I cannot teach you to take action, I cannot teach you to reach out and ask for help and ask questions I cannot teach you to not give up. That is something that you have to be good at yourself, okay, you have to have the resolve, you have to have the drive and the desire more than just the motivation to go forward. Okay, that I can't teach. But if you have that skill set, okay, if you've earned it, or learned it, or whatever, that kind of stuff. The rest is, is easy for me, I can teach you how to code, right? This is that that part's simple. Okay, that's just time. That's all that is. And once you get through the other end, I will hire the heck out of you if you know. So anyway, long story short. In my opinion, the coding boot camp is the solution. It is the path to employment, okay, to starting a new career, there are plenty of entry level jobs, for coders who are good enough, and you will be good enough if you go through the boot camp. And once you're beyond that, once you've had a year or two of experience, the world becomes your oyster. I know I've said this before, but it is so so true. as true today as it has ever been. There are just so many people, so many recruiters banging down my door banging down the doors of all senior programmers out there desperately trying to find people to, to fill the holes in the hiring process of other companies. So so many companies are looking for programmers who are qualified and they just can't find them fast enough. Okay, as myself as a business owner, as an employer, myself, I have felt this pain before I have felt the pain of Oh, no, I need more people. And I don't think I can find them. Or it's very, very difficult to find these people. Okay, I felt that pain before, not with programmers specifically with a different role. But now Now I understand the pain of Oh, no, like, where do I go to get these people? If I can't get these people? What am I going to do, I'm going to be in trouble. And that is the exact feeling that these employers have with respect to hiring programmers. So that's why I've taken it on myself my mission to train people on how to become the next generation of great coders. So we can fill those gaps, help those employers and help you at the same time. Okay, the university education and the university system, at least in North America, from what I've seen, falls very short of being able to fulfill this promise of allowing you to be job ready, and allowing you to go into one of these roles and understand what's going on. Okay, being able to hit the ground running. Okay? I haven't I just It still hasn't changed. Every every student I speak to every university student I speak to, they all repeat the same thing. I don't feel like I'm ready. Okay, and they're not I know, because I was one of them before. With a boot camp students, I just had a student last week, who's gone through the boot camp who is is pretty much graduate at this point. They're just waiting for their final review on their on their final project. They got a practice coding assignment that they needed to do. So they applied to a job. And they were given a practice coding assignment to fill out. And this student started to work on the practice coding assignment. They read through the requirements for the coding assignment, and they said, Oh, this looks exactly like assignment, I think nine or something in the curriculum in my boot camp. They're like, Oh, it's it's just assignment or assignment. 10, I think it was, they're like, Oh, this is just assignment 10 with different names, right? Different names, meaning different, different domain objects anyway.

28:57
But it was a, it was a simple assignment of, you know, you need to be able to do the CRUD operations on calling an API. And they were like, Oh, I've done that before. And they wrote able to code 95% of the project. And then they hit the last 5%, where it's at, okay, now, you did do that these XYZ things. And they were like, Ah, I'm, I haven't done that before. And that's always going to happen, right? I can only you can only know so much until there's that last 5% that you need to look up yourself. So guess what, they had the skill to be able to first reach out and ask for help. And I said, good question. Go google it. Right. And then they went in the Google that. And they're like, Oh, I think this is the way to do it. And I said, Yes, that's the way to do it. So this, you're learning. I'm teaching you guys on the podcast, as well as the bootcamp how to prepare for the real world. And I just see this every single time where students are like, Oh, they get their first you know, project on the job, or they get their first practice assignment. And they're like, Oh, that was assignment three here. That was assignment. 10. That was assignment six. So that was assignment and I say, Wow, imagine that shocking. Like, I keep saying a lot. I base my assignments off of the real world, but it doesn't really sink in. It sounds like marketing. But when you see it happening in the in in front of you when you are living the promise that the marketing talks about, you go, Oh, that's really helpful. Thank you, Trevor. And I'm like, okay, good. You're welcome. So anyway, I'm talking way too long than I meant to about this, but I just wanted to share some stories. And if you are someone who suffers from the I'm not good enough syndrome, and the I don't think I could ever make it syndrome, and everyone else can do it, but maybe not me, or I'm gonna be able to deserve this. I don't know, whatever you're struggling with. I've heard it all before. I've seen it all before. What it comes down to is the drive Do you want this or not? Okay, and do you want this soon? Do you want this in the next six to maybe nine months? Okay, or do you want to wait 18 or 24 or 36 months, I have, I cannot count the number of posts, I have seen on StackOverflow or not Stack Overflow on like Reddit, of people saying, oh my god, I got my first job, Yay, I'm a programmer. This is you know, I'm a self taught and I knew I can do it on my own. And that's great. I'm very, very happy for those people. I, I'm thrilled that they made it out. That's the goal. That's the dream. But then you read their story. And it's like, yeah, I started learning how to code, you know, 17 years ago, and it's like, Oh, my God, that's an exaggeration. But maybe they said, you know, three years ago, two years ago, and it's like, well, if you if you're okay, with waiting two years, great. But if you're in a situation where you want this, now, you want the salary, now you want the the outcome now, and you're ready to go. Now, boot camps are cheaper.

31:45
Okay, learning on your own might be free. But the opportunity cost that you give up, learning on your own and stumbling for two or three or four years, that has immense cost. So if you are ready to go now, if you want this stuff now, if you are more than motivated. Now, if you are driven. Now, if you will stop at nothing to unlock the career stability and an income, you know, now, if you want to, like, boot camps are the way to go. Okay, there's nothing I've seen that goes faster than boot camps. So I'm sorry, this is I did not mean to speak this long about this subject. But I just want to get that point across. So if you're still listening, and if this is actually, if you're listening on purpose, meaning if you're just doing the dishes, and your hands are wet, and you can't turn off the phone and skip what I'm saying, I'm very sorry, I will stop talking very, very soon. But if you're purposefully listening to this, if you're making the choice to listen to this, and you are considering it, and if this is striking a nerve with you, and making you feel like maybe I should check this thing out. I know it costs money, okay, it does cost money. But we're trying to structure it in such a way that you pay as absolutely the least amount of money as you possibly can to just cover the cost of the boot camp. Okay, just just my I don't take any profit at all, from this arrangement. And I'm saying this, I probably shouldn't be saying this out loud, because I don't know what this offer is going to be forever from now. But currently, as it stands right now, we're trying to make it so you can pay just the cost, meaning you only pay for the cost of the support that you're going to receive in the bootcamp and that's it. And the rest is could be potentially put into something called an income share agreement, where you don't pay that amount until you get a job as a coder making like $60,000 a year or more something right? Now, don't quote me on that I need to, I'm still ironing out the details. And I'm gonna get yelled at by my team for saying this out loud. But maybe they don't know they don't listen to the podcast. So I'm trying to structure it so that you pay the least amount of money as possible just to get the in, get in, get the education, and then you don't pay a cent until I get you out the other end and I help you to get that job. Once you have a job as a programmer, then you pay the rest of the balance. Right, that's sort of the deal that we're trying to structure. So that way I am I've always been motivated and incentivized to get jobs for my students that has never changed. But now I'm putting my money where my mouth is even more so by saying, Look, if you don't get a job as a coder, if you're if you don't get a job making less than 60k, then you don't pay back anything. And that's okay. There's no legal ramifications, that means I have failed. Okay, so long as you graduate, I should say that is the current stipulation, you need to graduate which means you need to do the work you need to show up you need to attend, you know, and do the assignments and follow my instructions, right if you choose to not follow my instructions and choose to not do any work and not show up and drop out, well, I can't help you. I'm not going to guarantee you a job and you're still gonna have to pay a penalty for that. Because that's you tapping out not me. This can be done as long as you're ready. As long as you're driven and you're willing to show up. I can I can extend that offer to you now you should also stay. Because I'm saying this out loud. The stipulation is for certain countries, for there are certain countries where even if you're the top developer, you're the best developer in on the planet, you're still not going to make $60,000 a year. That's just the way you know, global economics work. So this offer is limited to certain countries where, you know, your entry level salary is on average for a programmer. $60,000. Right. Yeah. So in other words, North America, some countries in Europe and whatnot. That's what this applies to. So I should make that that distinction now. But yeah, that's, that tends to be the majority of the people listening to the podcast, I'm very sorry, if you live in Pakistan, or India or something, and you're looking to get that kind of deal that education, I'm sorry, but it's just too expensive. And there's nothing I can do to solve global economic issues like that. Anyway, okay. I will stop talking. So coderscampus.com/bootcamp. If you are interested, now is the time to reach out. As soon as I release this podcast, reach out. You know, you go to the website, coders campus.com/boot camp and click to talk to us or whatever apply, send us a message, whatever, however you want to get in touch and say, Hey, I heard Trevor talking on the podcast about this offer where I only pay, you know, the cost of the bootcamp. I don't pay any anything else until I graduate and get a job and make $60,000 a year I want that offer. Right. So if that's you if that sounds good. Go now, coderscampus.com/bootcamp. And you know, fill out an application form. And make sure you have at least you know, 10 to 20 hours a week free. Because if you have less than 10 hours a week free, it's just gonna take too long. And then you might as well just learn on your own. Cool. Cool, I will stop talking. Thank you very much. Until next time again, I've promised you we will be learning about it streams i NT streams in the next lesson. So look forward to seeing you there. Take care of yourself as always, Happy learning. And bye for now.

37:07
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

The post EP55 – How to Sort with Streams in Java appeared first on Coders Campus.

  continue reading

74 епізодів

すべてのエピソード

×
 
Loading …

Ласкаво просимо до Player FM!

Player FM сканує Інтернет для отримання високоякісних подкастів, щоб ви могли насолоджуватися ними зараз. Це найкращий додаток для подкастів, який працює на Android, iPhone і веб-сторінці. Реєстрація для синхронізації підписок між пристроями.

 

Короткий довідник