Write java code to print "Hello how are you"
Thread1 should have "Hello"
Thread2 should have "how are you"
both the threads should start at the same time

Answer Posted / nil

We can have a simple program, I have issues with staring 2
threads at the same time, you guys can have a look and let
me know how could i start two threads at the same time.


the code is as follows, we would have a separate class for
each thread, and then we would have a tester class

package threads;

public class Thread1 implements Runnable{

public void run() {
System.out.println("Hello how are you");
}
}

package threads;

public class Thread2 implements Runnable{

public void run() {
System.out.println("Hello");
}
}



then this would be the tester class


package threads;

public class Thread_test {

public static void main(String[] args) {
Thread thread1 = new Thread(new Thread1());
Thread thread2 = new Thread(new Thread2());
thread1.start(); /* starting the two threads at the same
time, Any suggestions */
thread2.start();

}
}

Is This Answer Correct ?    0 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between a loader and a compiler?

530


Which sorting is used in arrays sort in java?

590


What is string value?

640


What is java virtual machine? Explain

571


What is class level lock ?

614






Is vector thread safe in java?

565


Write a java program to check if a number is prime or not?

539


What is close method? How it's different from Finalize & Dispose?

567


Define reflection.

577


What languages are pass by reference?

545


when a request is generated from apache tomcat 5.5 and goes to oracle 10g or mysql,,, how the oracle or mysql reads the request as apache is a web server and oracle 10g is application server? when the oracle 10g provides response, how the apche tomcat reads it???

1678


Can we override a variable in java?

556


Is java an open source?

530


What is the use of optional ?

572


When do we use synchronized blocks and advantages of using synchronized blocks?

669