Java Programming and Web Technologies Quiz
A mixed quiz covering Java programming concepts, SQL database queries, and HTML/SSI web technologies
Questions
A monitor called nik has 3 threads, having same priority, in its waiting pool; How can we notify one of the threads, named 'thread1' to move from Waiting state to Ready
- Execute notify(thread1); from within synchronized code of mon.
- Execute mon.notify(thread1); from synchronized code of any object.
- Execute thread1.notify(); from synchronized code of any object.
- Execute thread1.notify(); from any code(synchronized or not) of any object.
- You cannot specify which thread will get notified.
What of the following fails to cause a thread stop executing ?
- The program exits via a call to System.exit(0);
- Another thread is given a higher priority.
- A call to the thread's stop method.
- A call to the halt method of the Thread class.
A monitor called nik has 3 threads, having same priority, in its waiting pool; How can we notify one of the threads, named 'thread1' to move from Waiting state to Ready State?
- Execute notify(thread1); from within synchronized code of mon.
- Execute mon.notify(thread1); from synchronized code of any object.
- Execute thread1.notify(); from synchronized code of any object.
- Execute thread1.notify(); from any code(synchronized or not) of any object.
- You cannot specify which thread will get notified.
What of the following fails to cause a thread stop executing ?
- The program exits via a call to System.exit(0);
- Another thread is given a higher priority.
- A call to the thread's stop method.
- A call to the halt method of the Thread class.
Program output : package com.collection.examples; import java.util.HashSet; public class HashSetExample { public static void main(String[] args) { HashSet s = new HashSet();//1 for(short i = 0; i<100;i++){ //2 s.add(i); //3 s.remove(i-1); //4 } System.out.println(s.size()); //5 } }
- NumberFormat Exception
- 100
- Compilation fails at line 4
- 99
Which of the following options is true for the following program: try { if (choice) { while (true) } else { system .exit(1): } }finally { codetocleanup(); }
- Runtime Exception
- finally block will be executed
- finally block will not be executed
- Compilation error in else block