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

how we can make a read-only class in java?

0 Answers  


Is the milky way in a void?

0 Answers  


how jvm allocates memory for stack?

1 Answers   HP, Ramco,


What things should be kept in mind while creating your own exceptions in java?

0 Answers  


What’s the difference between the methods sleep() and wait()?

0 Answers  


Can we override singleton class?

0 Answers  


Is java a digit method?

0 Answers  


Define Multiprogramming and Multiprocessing in java.

0 Answers   Akamai Technologies,


What is java reflection api?

0 Answers  


What is a pattern what is an anti pattern?

0 Answers  


What is defined as false sharing in the context of multithreading?

0 Answers  


What is stringjoiner ?

0 Answers  


Categories