Hi Naveen Reddy garu, Please make a video on complete collections. U have so much knowledge in java and superb explanation.Every one will understand your videos.
It will also work the same, even if you create objects of the Class itself and not Runnable interface FirstThread firstThread = new FirstThread(); SecondThread secondThread = new SecondThread(); Thread t1 = new Thread(firstThread); Thread t2 = new Thread(secondThread); t1.start(); Thread.sleep(10); t2.start();
i have a doubt.What is the difference between "different threads with different instance of the class and different threads with the same instance of the class" ?
we can ,but it treats like a normal method actually when we call start() method,its look like this public void start(){ run(); //some other code } and more over if don't use start method we cant achieve multithreading
If you write obj1.run() it will run normally but here you want it to run like a thread (because we are learning multithreading). If you want it to run like a thread you need methods from Thread class.
Runnable is an interface but Thread is a class. so once you extend the Thread you can't extend any other class. but when you implement Runnable you can chance to extend the class if any.
@Telusko Hi! How did you go to the declaration of the interface runnable at 0:47? Which shortcut did you use? Kindly tell me how to see the documentation using that keyboard shortcut?
There is one thread in each program execution that is main. So while we are executing the main thread it is a single thread and executes each command line by line. But here when we are writing t1.start() and then it t2.start() then it should execute the t1.start() command completely and then only go to the next line. Could you please explain this?
t1 is a thread so it works on its own, main thread simples moves on after invoking thread t1. t1 thread's process is taken care by t1 thread not main thread.
we are not creating object of interface Actually we are creating object of class 'Hi' and 'Hello' new keyword is used to create object and observe that it used for classes
why we used runnable in the following statements :- Runnable obj1 = new Hi(); Runnable obj1 = new Hello(); And also why we are not writing obj1 and obj2 in t1.start() and t2.start() resp ?
if u write few lines of code after calling the start method,why those codes execute first??? t1.start(); try{Thread.sleep(10);}catch(InterruptedException e){System.out.println(e);} t2.start(); System.out.println("happy codding"); and it gives output like this happy codding Thread 1 Thread 2 Thread 1 Thread 2
prefect he is really smart talking and not make you feel sleepy he knows how to deal with record voice
Hi Naveen Reddy garu,
Please make a video on complete collections.
U have so much knowledge in java and superb explanation.Every one will understand your videos.
I'm watching this after 5 years and it still helped me a lot!
No words to describe about your teaching sir......... 👏👏👏👏👏👏👏
the way of teaching is really understandable in all the videos.... thank you so much. and the beginning music also nice !!!
Thank you, Sir!!!
This helps a lot for me.
4:04 Hi Hello was sounding like "Hi Hiku Hi Hiku, hi hi..." , btw your teaching is the best.
wow u hav clarity!!n i love people who hav clarity in their ideas!!!!!!
Hi, how can we implement thread in spring projects , please provide the exact real time scenario. Thanks
Very easy to understand java when you teach us sir .....
Brilliant as usual, Mr Reddy...
Excellent Videos offered by you . keep going on
Excellent again
Perfect Telusko Binod!!!!
Hello from Poland !
Piter Admski hi
Ah sir can we have some more videos on Runnable and multithreading please :)
Excellent Video, But technically it is not an object of Runnable but reference of the interface Runnable.@4.35
Excellent video
Great job sir u r videos are very helpful
It will also work the same, even if you create objects of the Class itself and not Runnable interface
FirstThread firstThread = new FirstThread();
SecondThread secondThread = new SecondThread();
Thread t1 = new Thread(firstThread);
Thread t2 = new Thread(secondThread);
t1.start();
Thread.sleep(10);
t2.start();
Please make a video on completable future
I highly admire you, from tanzania
Why we are using the reference of runnable? Can we use interfaces to refer objects? Why? Please tell me 3:42
i have a doubt.What is the difference between "different threads with different instance of the class and different threads with the same instance of the class" ?
Wow that's really well explained! Thanks man
Thankyou sir ❤
hello,
how I do the synchronization with algorithm between multiple clients
what is the difference between an abstract class and an interface if have two methods in getting a thread
how is runnable interface linked to Thread class ?
nice concept sir.Thank you
so help full really
Sir, why cant we simply write
obj1.run();
instead of,
Thread t1 = new Thread(obj1);
t1.show();
we can ,but it treats like a normal method actually when we call start() method,its look like this
public void start(){
run();
//some other code
}
and more over if don't use start method we cant achieve multithreading
If you write obj1.run() it will run normally but here you want it to run like a thread (because we are learning multithreading). If you want it to run like a thread you need methods from Thread class.
Hi sir,
Why there are two ways to achieve multithreading?
What is the difference between using Runnable and Thread?
Runnable is an interface but Thread is a class. so once you extend the Thread you can't extend any other class. but when you implement Runnable you can chance to extend the class if any.
thnaku sir amazing explanation
@Telusko Hi! How did you go to the declaration of the interface runnable at 0:47? Which shortcut did you use? Kindly tell me how to see the documentation using that keyboard shortcut?
press ctrl+LMB(left mouse button or a simple click lol) while pointing the cursor on the keyword.
sir in this program switching will take place or not??
Even though i have entered the same code my output is five time hi folled by five times hello. Any help?
Sometimes it depends on your system processor also, don't think every system will gives u the same output
Nice video sir
There is one thread in each program execution that is main.
So while we are executing the main thread it is a single thread and executes each command line by line.
But here when we are writing t1.start() and then it t2.start() then it should execute the t1.start() command completely and then only go to the next line.
Could you please explain this?
t1 is a thread so it works on its own, main thread simples moves on after invoking thread t1. t1 thread's process is taken care by t1 thread not main thread.
hello , i cant see imported packages in that file you are coding in ?
Runnable, Thread come under java.lang package and this is imported in java by default.
thanks.. so helpful
I have a query, we cannot make object of an interface then why is it written -> 'Runnable' obj1 = new Hi(); or 'Runnable' obj2 = new Hello();
we are not creating object of interface
Actually we are creating object of class 'Hi' and 'Hello'
new keyword is used to create object and observe that it used for classes
Sir you have made me conquer java in no time.....for(int x=1;x
you can't be equal to infinity, get wreckt liberal
@@billysmith3399 it was just a figure of speech you dumb duck
Thanks
Sir when I'm running this code I'm getting 10 hi and hello each...Why?
he explained this in the previous video.
Very nice! 👍
Thank you....
why we used runnable in the following statements :-
Runnable obj1 = new Hi();
Runnable obj1 = new Hello();
And also why we are not writing obj1 and obj2 in t1.start() and t2.start() resp ?
I wrote Hi obj1 = new Hi(); and there was no difference.
Can anyone explain this code to me please!!!
class myThread implements Runnable{
Thread t;
myThread(){
//creates a my thread
t = new Thread(this , "Demo thread");
System.out.println("child thread : " +t);
}
//this is the entry point for 2nd thread
public void run(){
try{
for(int i=5 ;i>0 ; i--){
System.out.println("child thread : " +i);
Thread.sleep(500);
}
}catch(InterruptedException e){
System.out.println("child interrupted ");
}
System.out.println("exiting child thread ");
}
}
class ThreadDemo{
public static void main(String args[]){
myThread nt= new myThread();
nt.t.start();
try{
for(int i=5 ;i>0 ; i--){
System.out.println("MAIN thread : " +i);
Thread.sleep(1000);
}
}catch(InterruptedException e){
System.out.println("main thread interrupted ");
}
System.out.println("exiting main thread ");
}
}
if u write few lines of code after calling the start method,why those codes execute first???
t1.start();
try{Thread.sleep(10);}catch(InterruptedException e){System.out.println(e);}
t2.start();
System.out.println("happy codding");
and it gives output like this
happy codding
Thread 1
Thread 2
Thread 1
Thread 2
If you want to print "happy codding" in the end then you can use the join method.
cool
you are explaining very well, thx. I would say your videos are so good like the ones by thenewboston except you dont objectify your exs LOL
my.concept++;
I guess I'm gonna have to get used to this indian slur english if i'm gonna use youtube for java help
when i use start method it shows error but when i use run in it shows coorect ouput please answer me why this occurs
sorry when i call start method it shows error but when i call run it runs correctly
It's maybe bug just creat a new class and write again and now bingo u won't get output it will tell exception by the way same thing happened with me🤣