Hello, in this Java programming video, we are going to continue from the previous tutorial where we implemented a thread using the runnable interface. And we actually, you know, we implemented that interface, as you can see in the Fred runnable class right here. And we're going to modify this slightly. So we're going to create a thread by extending the thread class. So this is very similar, but it just provides more flexibility when creating multiple threads, and it's the preferred method of doing things. So the changes you'll have to make are pretty minimal, to be honest.
So recommend watching the first tutorial. Instead, we're going to extend the thread like so. We're gonna have you know, a thread we're going to have a name for it. We're gonna have a constructor, still gonna do the same thing like so. gonna print that out, that's fine. Then in the run method, we'll still have the printing intent, we'll have our for loop within the try catch block will still do some sleeping and will still have, you know the interruption handling and in the start method will still check if the thread has been created.
If not, it will create a new thread and you'll do your startup and then start to solve a system Java on it that is it. So if you run it there we go, it has now run so it created the threads, you started them and then it alternates. Obviously, the you know how the actual floor should say be the order of them will vary slightly depending on what else going on in your CPU. There will be various things going on when you run it, but this is the preferred method by extending the thread class. And what I'll do is I'll provide a link With this video, which shows you all of the extra, you know, functionality that you can add to a Fred an extra task, feel free to try and modify the Fred. So you can pass in a integer value.
So you can specify how long you should sleep for. And that way you can modify the sleep for another different Fred. Maybe Fred wanted a higher priority, so you want that to work a lot more. Well, this isn't and also add another task on top of that, once you've done it, feel free to try and create the 10th read the different tasks, different priorities, and maybe you initiate them as well. some pretty cool stuff that you can get started on. Thanks for watching, and I look forward to seeing the next awesome programming video.