Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 are runtime exceptions?

1123


What is stack class in java?

1004


Why string is not a wrapper class?

1154


String class is defined under which package in java?

1034


What is the purpose of the finally clause of a try-catch-finally statement in java programming?

906


What is a cup of java?

983


How to perform bubble sort in java?

963


What is the buffer limit?

996


What is the use of 'super' keyword inside a constructor?

924


What is bom encoding?

959


What is Java Reflection API? Why it’s so important to have?

1098


What is use of super keyword?

928


Difference between string, stringbuffer and stringbuilder?

994


What about static nested classes in java?

1092


What is the difference between the final method and abstract method?

1007