Java Programming and Web Technologies Quiz

A mixed quiz covering Java programming concepts, SQL database queries, and HTML/SSI web technologies

6 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

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

  1. Execute notify(thread1); from within synchronized code of mon.
  2. Execute mon.notify(thread1); from synchronized code of any object.
  3. Execute thread1.notify(); from synchronized code of any object.
  4. Execute thread1.notify(); from any code(synchronized or not) of any object.
  5. You cannot specify which thread will get notified.
Question 2 Multiple Choice (Single Answer)

What of the following fails to cause a thread stop executing ?

  1. The program exits via a call to System.exit(0);
  2. Another thread is given a higher priority.
  3. A call to the thread's stop method.
  4. A call to the halt method of the Thread class.
Question 3 Multiple Choice (Single Answer)

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?

  1. Execute notify(thread1); from within synchronized code of mon.
  2. Execute mon.notify(thread1); from synchronized code of any object.
  3. Execute thread1.notify(); from synchronized code of any object.
  4. Execute thread1.notify(); from any code(synchronized or not) of any object.
  5. You cannot specify which thread will get notified.
Question 4 Multiple Choice (Single Answer)

What of the following fails to cause a thread stop executing ?

  1. The program exits via a call to System.exit(0);
  2. Another thread is given a higher priority.
  3. A call to the thread's stop method.
  4. A call to the halt method of the Thread class.
Question 5 Multiple Choice (Single Answer)

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 } }

  1. NumberFormat Exception
  2. 100
  3. Compilation fails at line 4
  4. 99
Question 6 Multiple Choice (Single Answer)

Which of the following options is true for the following program: try { if (choice) { while (true) } else { system .exit(1): } }finally { codetocleanup(); }

  1. Runtime Exception
  2. finally block will be executed
  3. finally block will not be executed
  4. Compilation error in else block