Java Video Tutorial 17

Code Here:

Best Java Book :

In this Java Video Tutorial I cover how to use Java threads.

A thread is just a block of code that is expected to execute while other blocks of code execute. That’s it. When you want to execute more than one block of code at a time you have to alert Java.


TurnoverEwe0633 says:

its funny how “String” and “thread” in reality are types of unwoven fabric or cloth

John Zahmir Olaer says:

do you know how to calculate the difference of two dates?

soumen mitra says:

why my same code is giving error saying – Exception in thread “main” java.lang.RuntimeException: Uncompilable source code – constructor getTheMail in class getTheMail cannot be applied to given types;
required: no arguments
found: int
reason: actual and formal argument lists differ in length
at mainTime.main(
C:UsersuserAppDataLocalNetBeansCache8.2executor-snippetsrun.xml:53: Java returned: 1
BUILD FAILED (total time: 6 seconds)

E M says:

You should lock System.out for only 1 thread to use at a time.

Abdullah Al Sefat says:

Hey Derek. I’m from Bangladesh. From the beginning of my Java Course in my University I follow your videos. You are the reason of my good marks in Java till now. I never thought my country would be mentioned here. It felt good. Thanks for the awesome videos. 🙂

CodeBY says:

yesterday understand less than 50%
today understand everything…
Cool! 😀

subhadip Jana says:

Where is the runnable interface?

Philip Malan says:

7:00 getThemMail XD

Cheaper says:

The thing I love about your videos is they aren’t intimidating. Even if I don’t know something, I’m not scared away by it because you explain it so well. Keep up the great work! Glad to finally get an understanding of threads.

Kuljit Singh says:

// You can use the Runnable interface instead of
// wasting your 1 class extension.

i dont get it . Why did you use Runnable ? it is thread or interface ?

N N says:

Thank you

Simran Singh says:

You saved my head from getting blasted. Your tutorial helped me to get the use of thread.
wouldn’t that be great if you plan a day in a week or so to answer doubts real time.. only if it’s comfotable for you.. pls

Brentonr25 says:

Wanted to say thanks for your videos Derek, I finally have my first skills interview tomorrow for an entry level java position, and your videos have helped a bunch.

Piyush Kumar says:

+Derek Banas gr8 tutorials on java!!!!!!  Awesome way of teaching,,keep up the good work sir..!! 🙂

Prince Gupta says:

I’m din’ your series from this tutorial as I already new much. But now when I see the upcoming topics of your series , I just can’t wait. You’ve made the topics awesome. thank you.

Aaron Loomis says:

Derek, do you have a video on iterator implementation in Java?


I find we need this cord.

Thread getMailThread = new Thread(getmail);

But, you just used this.
new Thread(getMail).start();

how come you can use that one? I don’t get one.

Luka S. says:

Why we call object like this: Thread name = new Thread1(); and not like: Thread1 name = new Thread1();

Mr_Mc_Fuk_It says:

Hey Derek i have a quick question. In OOP language when creating a object/ instance you have to declare in this fashion
C++ (Class) (object name) (constructor); in Java (Class) (object name) = new (Class) (constructor);. in the case of the DateFormat
you created 2 instances timeFormatter & dateFormatter but did not use the syntax stated above. instead it uses a (Class)(Method)(args)
syntax. i have look around on the oracle website but no explanation as to why it is created this way can out elaborate on why it uses a
different syntax thanks 😀

Adam ahmed says:

3:00:05 AM
Jan 1, 1970  ……….. oh wow my PC is so old LOL

subhadip Jana says:

Hey Derek! Can you please recommend a good book for practicing Java .I feel learning java will only be half complete ,if I don’t practice these OOP concepts.

paul110 says:

OMG thank you so much for video. You saved my ass for college 😀

Space Mother Wolf says:

May I ask what the 2 threads exactly are? Are they “Date” and “Time”? Just making sure.

Denzal Martin says:

What is the difference between a class that implements runnable and a class that extends the thread class? Is there a benefit of using one or the other to create a thread?

Aditya Mandal says:

Do we need to explicitly define the default constructor or Java does it automatically?
At some places I found we need to define those but in here we didn’t define the default constructor GetTime20(). Am I missing something?

janos laszlo says:

this code does NOT check the mail every 10 seconds, it checks only once after 10 seconds for “getMail” and after 20 seconds for getMailAgain.

For 20 iterations with a sleep of 2 secs it should output “Checking mail” at least 4 times and when I test it it outputs “Checking mail” only twice.

Why is that?

soumen mitra says:

why the same code in my ide is giving me errors?

Silas Mcfarlane says:

Your videos are awesome though!!

Robo says:

dude you have the potential to post ‘A’ quality tutorials but you’re limiting yourself to ‘B’ because you dont take the time to talk about the theory and thought processes. Telling someone how to type a thread is easy but its when you teach someone how to KNOW how to build threads is what the students need. It just makes it so much more difficult to learn.

What needs to happen is you to go more in depth. think about your wordings more.


so what is object class

Alexandre Velasco says:

how do i do to remember all this stuff? is there any tricks for memorizing?
thanks. very good tutorial

Tra Realeco says:

So a thread runs infinite times until we stop it right?

Dan Danes says:

Dude.  Awesome stuff.  I am subscriber now. 

If I have several threads running and I want to run a command based on the last one that finishes.  How do I check for that. Is there a thread ends type event I can run an if statement against?

BlinG says:

It’s not printing “Checking Mail” for me. Any ideas?

Here is my GetTheMail class:

My GetTime20 class:

and my JavaLessonSeventeen class:

Bo Wen says:

Can you use GetTheMail class to extend the thread class, instead of implementing the Runnable interface?

Madham Naren says:

Sir! how to avoid execution of finally block….?? please tell me any three methods to do so….

Silas Mcfarlane says:

Hi Derek, lots of the time I watch the videos on my iPad mini and I can’t right down the code cause someone else is using the computer! Some things I do not get probably cause I am only 12 years old! Do you know a way or practice that can help me better understand??

muj62k says:

Hey, I’d like to ask you to help me … I’m facing a problem with the methods , it’s hard to memorize this number of methods in java .. thank you

Pj Cohen says:

why did you write Runnable?

Reflex F.N. says:

Why does the GetTheMail thread stop when the GetTheTime thread stops? We didn’t use a for-loop in the GetTheMail thread, yet it stopped executing when GetTheTime stopped.

Lightning theBeast says:

I was kinda imagining of my country Bangladesh when you were stating the different languages . Felt epic when you said that .
As always , you made an epic video

Tahmidur Rahman says:

It felt so great when u said the name “Bangladesh”.
I hope within 30 years i’ll be as cool as u 😉
Such an awesome guy you are.Respect from Bangladesh!

요세미티 says:

What is ‘Runnable getMail = new GetTheMail(10);’?
Is it same as ‘GetTheMail getMail = new GetTheMail(10);’?

Sven Austen says:

How can I get output that is not a String, Integer or stuff like that but something like a green circle or maybe a more complex shape? Do I need another program or can I maybe just modify the “System.out.” command?

Ashwin murali says:

Hello Derek 🙂 I have a question.. The constructor of the thread class only accepts objects of classes that have implemented the runnable interface.. How can we do something similar with our classes?? I mean like having an interface implementation as a must…

Thank you!

Prashob Mathiyambath says:

Dear Derek this was hard to understand as you did’nt explain what threads are and other underlying details.

Philip Malan says:

I found that you can display input while entering in an input in the console using threading O.O

Xinyan Huang says:

Why do you not use the GetTime20 getTime = new GetTime20(); instead of using the Thread getTime = new GetTime20();?

 Write a comment


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!