Select chapter



basics (7.papers)
constructors (1.papers)
packages (1.papers)
inheritance (7.papers)
misc (3.papers)
exceptions (5.papers)
threads (4.papers)
overloading (1.papers)
jsp (3.papers)
servlets (9.papers)
jdbc (2.papers)
util (1.papers)
xml (2.papers)
IO stream (3.papers)
Hide

Sponsored Links


  

java interview questions and answers

1
How to interrupt a sleeping thread in Java?
  1. Call the interrupt() method on your thread. This will cause the sleep to be cancelled and an InterruptedException will be thrown.
  2. return from run() method to interrupt a sleeping thread.
  3. call join() on the thread which is sleeping, to interrupt it.
  4. all are true.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
10
Consider the following classes: 
public class TestThread  implements Runnable{ 
 public void run(){ 
  System.out.print("Inside runnable");  } 
 public static void main(String args[])  { 
  TestThread o=new TestThread(); //line 5
  Thread t=new Thread(o); //line 6 
  t.start();//line 7 
 }  
}
 Which one statement below is true?
  1. the code will compile correctly and will execute without throwing any exceptions
  2. there will be a compiler error at line 6, because you can not pass a a parameter to the constructor of a thread
  3. the code will compile correctly but will crash with an exception at line 6.
  4. the code will compile correctly but will crash with an exception at line 7
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
13
What could be a part of the output of compiling and running the following code?
public class Tester extends Thread {
 public void run() {
  System.out.println("run");
 }
 public static void main(String[] args) {
  Thread thread = new Tester();
  thread.run();
  thread.start();
  thread.start();
 }
}
  1. Compilation error
    
  2. Prints “run” twice, not necessarily consecutively. IllegalThreadStateException will be thrown
  3. InterruptedException will be thrown
    
  4. Prints “run” twice and IllegalThreadStateException will be thrown
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Read more papers :