what is use of threads how many ways to create thread

Answers were Sorted based on User's Feedback



what is use of threads how many ways to create thread..

Answer / madhusudhan

use of thread:1.concurrent execution of thread.
2.Program security.
Thread can be create in 2 ways
1.using Thread class
2.using Runnable interface
Example:
//first way of creating thread
class Thread1 extends Thread
{
public void run()
{
for(int i=0;i<1000;i++)
{
System.out.println(hashcode()+":"+i);
}
}
}
//second way of creating thread
class Thread2 implements Runnable
{
public void run()
{
for(int i=1000;i<2000;i++)
{
System.out.println(hashcode()+":"+i);
}
}
}
public class M
{
public static void main(String args[])
{
Thread1 t1=new Thread1();
t1.start();
Thread2 t2=new Thread2();
Thread t=new Thread(t2);
t.start();
}
}

Is This Answer Correct ?    22 Yes 1 No

what is use of threads how many ways to create thread..

Answer / subash chandra bose l

there are many uses of threads and the main use is to
execute several process at once.

there are two ways of creating a thread and

1. extending a Thread class
2. implementing Runnable interface

Is This Answer Correct ?    8 Yes 1 No

what is use of threads how many ways to create thread..

Answer / poorna chandar rao.yerrabothu

thread is light whight processes its take low memory and low
proceesing time
there are two types thereds creatd
extending the thered class
implementing the runnable interface

Is This Answer Correct ?    4 Yes 2 No

Post New Answer

More Core Java Interview Questions

can any one send me the example program of immutable class?

2 Answers   Arfin, TCS,


What is a parameter in a function?

0 Answers  


What is difference between static method and static variable?

7 Answers  


Why Java doesn’t support multiple inheritance?

0 Answers  


How use .contains in java?

0 Answers  






What is the default size of load factor in hashing based collection?

0 Answers  


Explain why wait(), notify() and notifyall() methods are in object class rather than in thread class?

0 Answers  


What are triggers in DB? Explain their types. How do they work?

0 Answers   Amdocs,


why java is not supporting multiple inheritence?

3 Answers  


Can java list contain duplicates?

0 Answers  


is memory to the abstract class allocated ..or objects not instantiated

7 Answers   Synechron, TCS,


Is java a utf 8 string?

0 Answers  


Categories