Monday, 21 December 2015

Thread Concurrency Java - MCQ set 1 (30 questions, 68 marks)

Thread Concurrency Java - MCQ set 1 (30 questions, 68 marks)



    Q1 - Q22, 22 MEDIUM level difficulty questions 2 mark each. 2 * 22 = 44 marks 

  1. Semaphore is found in which package in thread concurrency in java?

  2. a.java.util.concurrent
    b.java.util
    c.java.io
    d.java.lang

  3. Semaphore was introduced in which java version

  4. a.java 5
    b.Java 6
    c.java 7
    d.java 8

  5. Semaphore is a class/interface/abstract class/other?

  6. a.Class
    b.Interface
    c.Abstract class
    d.Other

  7. Callable is found in which package in thread concurrency in java?

  8. a.java.util.concurrent
    b.java.util
    c.java.io
    d.java.lang

  9. Callable was introduced in which java version

  10. a.java 5
    b.Java 6
    c.java 7
    d.java 8

  11. Callable is a class/interface/abstract class/other?

  12. a.Class
    b.Interface
    c.Abstract class
    d.Other

  13. Future is found in which package in thread concurrency in java?

  14. a.java.util.concurrent
    b.java.util
    c.java.io
    d.java.lang

  15. Future was introduced in which java version

  16. a.java 5
    b.Java 6
    c.java 7
    d.java 8

  17. Future is a class/interface/abstract class/other?

  18. a.Class
    b.Interface
    c.Abstract class
    d.Other

  19. RecursiveTask is found in which package in thread concurrency in java?

  20. a.java.util.concurrent
    b.java.util
    c.java.io
    d.java.lang

  21. RecursiveTask was introduced in which java version

  22. a.java 5
    b.Java 6
    c.java 7
    d.java 8

  23. RecursiveTask is a class/interface/abstract class/other?

  24. a.Class
    b.Interface
    c.Abstract class
    d.Other

  25. ForkJoinTask is found in which package in thread concurrency in java?

  26. a.java.util.concurrent
    b.java.util
    c.java.io
    d.java.lang

  27. ForkJoinTask was introduced in which java version

  28. a.java 5
    b.Java 6
    c.java 7
    d.java 8

  29. ForkJoinTask is a class/interface/abstract class/other?

  30. a.Class
    b.Interface
    c.Abstract class
    d.Other

  31. RecursiveAction is found in which package in thread concurrency in java?

  32. a.java.util.concurrent
    b.java.util
    c.java.io
    d.java.lang

  33. RecursiveAction was introduced in which java version

  34. a.java 5
    b.Java 6
    c.java 7
    d.java 8

  35. RecursiveAction is a class/interface/abstract class/other?

  36. a.Class
    b.Interface
    c.Abstract class
    d.Other

  37. ForkJoinPool is found in which package in thread concurrency in java?

  38. a.java.util.concurrent
    b.java.util
    c.java.io
    d.java.lang

  39. ForkJoinPool was introduced in which java version

  40. a.java 5
    b.Java 6
    c.java 7
    d.java 8

  41. ForkJoinPool is a class/interface/abstract class/other?

  42. a.Class
    b.Interface
    c.Abstract class
    d.Other

  43. What method of java.util.concurrent.Callable interface returns value

  44. a.calling() method
    b.run() method
    c.runnable() method
    d.call() method



    Q23 - Q30, 8 HARD level difficulty questions 3 mark each.       3 * 8 = 24 marks

  45. What is significance of using Fork/Join Framework in thread concurrency in java?

  46. a.Fork/Join Framework has been added in JDK 7
    b.Fork/Join framework enables parallel programming. Parallel programming improves program performance
    c.Parallel programming means taking advantage two or more processors (multicore) in computers.
    d.All

  47. What approach does java.util.concurrent.ForkJoinPool uses for managing tasks?

  48. a.Data modelling approach
    b.Observing approach
    c.Behavioural approach
    d.work-stealing approach

  49. What is true about java.util.concurrent.RecursiveTask in thread concurrency in java?

  50. a.It provides calculate() for submitting a task but it does not return a result
    b.It provides compute() for submitting a task and returning a result
    c.It provides calculate() for submitting a task and returning a result
    d.It provides compute() for submitting a task but it does not return a result

  51. What is valid about synchronized and java.util.concurrent.locks.ReentrantLock in thread concurrency in java

  52. a.synchronized Does not provide any fair locks.
    b.ReentrantLock provides fair lock
    c.ReentrantLock provides getQueueLength() method to return number of threads that may be waiting to acquire this lock.
    d.All

  53. What is valid about call method of Callable interface in thread concurrency in java?

  54. a.call() method can only throw an exception if unable to calculate result.
    b.call() method returns computed result or throws an exception if unable to do so
    c.call() method returns computed result but cannot throw an exception if unable to do so
    d.call() method cannot return result

  55. Which method can be used to find whether lock is held by current thread?

  56. a.findLockHold()
    b.isLockHeld()
    c.holdsLock()
    d.lockHold()

  57. What is valid about java.util.concurrent.CountDownLatch in thread concurrency in java?

  58. a.java.util.concurrent.CountDownLatch can be used to launch event
    b.for completing wait in java.util.concurrent.CountDownLatch specified number of threads must call countDown() method
    c.java.util.concurrent.CountDownLatch can be awaited repeatedly
    d.None of these

  59. What is valid about arrive() and arriveAndAwaitAdvance() method of java.util.concurrent.Phaser in thread concurrency in java?

  60. a.arrive() method of java.util.concurrent.Phaser does not cause current thread to wait for other registered threads to complete current phase
    b.arriveAndAwaitAdvance() method causes current thread to wait for other registered threads to completecurrent phase
    c.All
    d.None




Quiz 1 - Correct answers



MEDIUM
1) a
2) a
3) a
4) a
5) a
6) b
7) a
8) a
9) b
10) a

11) c
12) c
13) a
14) c
15) c
16) a
17) c
18) c
19) a
20) c

21) a
22) d

HARD
23) d
24) d
25) b
26) d
27) b
28) c
29) b
30) c

Go to TOP of the page




Thread Concurrency Java - MCQ set 2 (30 questions, 68 marks)



    Q1 - Q22, 22 MEDIUM level difficulty questions 2 mark each. 2 * 22 = 44 marks 

  1. Lock is found in which package in thread concurrency in java?

  2. a.java.util.concurrent.locks
    b.java.util
    c.java.util.locks
    d.java.util.concurrent

  3. Lock was introduced in which java version

  4. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8

  5. Lock is a class/interface/abstract class/other?

  6. a.Class
    b.Interface
    c.Abstract class
    d.Other

  7. ReentrantLock is found in which package in thread concurrency in java?

  8. a.java.util.concurrent.locks
    b.java.util
    c.java.util.locks
    d.java.util.concurrent

  9. ReentrantLock was introduced in which java version

  10. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8

  11. ReentrantLock is a class/interface/abstract class/other?

  12. a.Class
    b.Interface
    c.Abstract class
    d.Other

  13. ReadWriteLock is found in which package in thread concurrency in java?

  14. a.java.util.concurrent.locks
    b.java.util
    c.java.util.locks
    d.java.util.concurrent

  15. ReadWriteLock was introduced in which java version

  16. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8

  17. ReadWriteLock is a class/interface/abstract class/other?

  18. a.Class
    b.Interface
    c.Abstract class
    d.Other

  19. ReentrantReadWriteLock is found in which package in thread concurrency in java?

  20. a.java.util.concurrent.locks
    b.java.util
    c.java.util.locks
    d.java.util.concurrent

  21. ReentrantReadWriteLock was introduced in which java version

  22. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8

  23. ReentrantReadWriteLock is a class/interface/abstract class/other?

  24. a.Class
    b.Interface
    c.Abstract class
    d.Other

  25. CountDownLatch is found in which package in thread concurrency in java?

  26. a.java.util.concurrent
    b.java.util
    c.java.io
    d.java.lang

  27. CountDownLatch was introduced in which java version

  28. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8

  29. CountDownLatch is a class/interface/abstract class/other?

  30. a.Class
    b.Interface
    c.Abstract class
    d.Other

  31. CyclicBarrier is found in which package in thread concurrency in java?

  32. a.java.util.concurrent
    b.java.util
    c.java.io
    d.java.lang

  33. CyclicBarrier was introduced in which java version

  34. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8

  35. CyclicBarrier is a class/interface/abstract class/other?

  36. a.Class
    b.Interface
    c.Abstract class
    d.Other

  37. Phaser is found in which package in thread concurrency in java?

  38. a.java.util.concurrent
    b.java.util
    c.java.io
    d.java.lang

  39. Phaser was introduced in which java version

  40. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8

  41. Phaser is a class/interface/abstract class/other?

  42. a.Class
    b.Interface
    c.Abstract class
    d.Other

  43. Exchanger is found in which package in thread concurrency in java?

  44. a.java.util.concurrent
    b.java.util
    c.java.io
    d.java.lang



    Q23 - Q30, 8 HARD level difficulty questions 3 mark each.       3 * 8 = 24 marks

  45. What are important methods of java.util.concurrent.atomic.AtomicInteger

  46. a.get()
    b.set()
    c.getAndSet(int newValue)
    d.all()

  47. What is valid about run method of java.lang.Runnable interface?

  48. a.run() method can only throw an exception if unable to calculate result.
    b.run() method returns computed result or throws an exception if unable to do so
    c.run() method does not return a result and can neither throw a checked exception
    d.run() method returns computed result but cannot throw an exception if unable to do so

  49. What does CountDownLatch(int count) constructor specifies?

  50. a.CountDownLatch is initialized with given count.
    b.count specifies the number of events that must occur before latch is released.
    c.Once count reaches 0 latch is released.
    d.All of these

  51. What happens in java.util.concurrent.CyclicBarrier class?

  52. a.2 or more threads wait for each other to reach a common barrier point.
    b.When all threads have reached common barrier point (i.e. when all threads have called await() method) all waiting threads are released
    c.When all threads have reached common barrier point (i.e. when all threads have called await() method) event can be triggered as well
    d.All

  53. What is valid about java.util.concurrent.Phaser class?

  54. a.Phaser provides us flexibility of registering and deRegistering parties at any time
    b.Phaser allows us registering and deRegistering parties in constructor only
    c.Phaser can't be awaited repeatedly
    d.All

  55. java.util.concurrent.Phaser provides which of the following for registering parties/thread?

  56. a.register() method
    b.bulkRegister(int parties) method
    c.constructor = Phaser(int parties)
    d.All

  57. We could override onAdvance() method of java.util.concurrent.Phaser to?

  58. a.advance to previous phase
    b.register the parties/threads for next phase
    c.control number of phases which we want to execute.
    d.All

  59. When Phaser is terminated?

  60. a.When calling arriveAndDeregister() method of Phaser has caused the number of registered parties to become 0.
    b.Termination can also be triggered when an onAdvance() method returns true.
    c.All
    d.None of these




Quiz 2 - Correct answers



MEDIUM
1) a
2) a
3) b
4) a
5) a
6) a
7) a
8) a
9) b
10) a

11) a
12) a
13) a
14) a
15) a
16) a
17) a
18) a
19) a
20) c

21) a
22) a

HARD
23) d
24) c
25) d
26) d
27) a
28) d
29) c
30) c

Go to TOP of the page




Thread Concurrency Java - MCQ set 3 (30 questions, 68 marks)



    Q1 - Q22, 22 MEDIUM level difficulty questions 2 mark each. 2 * 22 = 44 marks 

  1. What is java.util.concurrent.semaphore class

  2. a.provides parallel programming
    b.cannot controls access to a shared resource
    c.controls access to a shared resource by using permits
    d.None

  3. What are important methods provided by Semaphore in maintaining concurrency

  4. a.acquire()/release() methods
    b.conquer()/release() methods
    c.acquire()/drop() methods
    d.conquer()/drop() methods

  5. Exchanger was introduced in which java version

  6. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8

  7. Exchanger is a class/interface/abstract class/other?

  8. a.Class
    b.Interface
    c.Abstract class
    d.Other

  9. Which concurrency class/Interface/framework uses Divide-and-conquer strategy?

  10. a.Semaphore
    b.Phaser
    c.CyclicBarrier
    d.Fork/Join framework

  11. What is valid about Executor service framework in java

  12. a.creates thread
    b.starts threads
    c.manages whole life cycle of Threads.
    d.All

  13. AtomicInteger is found in which package?

  14. a.java.util.concurrent.atomic
    b.java.util
    c.java.util.atomic
    d.java.util.concurrent
    e.It doesn't exists till Java 8

  15. AtomicInteger was introduced in which java version

  16. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8
    e.It doesn't exists till Java 8

  17. AtomicInteger is a class/interface/abstract class/other?

  18. a.Class
    b.Interface
    c.Abstract class
    d.Other
    e.It doesn't exists till Java 8

  19. AtomicLong is found in which package?

  20. a.java.util.concurrent.atomic
    b.java.util
    c.java.util.atomic
    d.java.util.concurrent
    e.It doesn't exists till Java 8

  21. AtomicLong was introduced in which java version

  22. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8
    e.It doesn't exists till Java 8

  23. AtomicLong is a class/interface/abstract class/other?

  24. a.Class
    b.Interface
    c.Abstract class
    d.Other
    e.It doesn't exists till Java 8

  25. AtomicDouble is found in which package?

  26. a.java.util.concurrent.atomic
    b.java.util
    c.java.util.atomic
    d.java.util.concurrent
    e.It doesn't exists till Java 8

  27. AtomicDouble was introduced in which java version

  28. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8
    e.It doesn't exists till Java 8

  29. AtomicDouble is a class/interface/abstract class/other?

  30. a.Class
    b.Interface
    c.Abstract class
    d.Other
    e.It doesn't exists till Java 8

  31. AtomicBoolean is found in which package?

  32. a.java.util.concurrent.atomic
    b.java.util
    c.java.util.atomic
    d.java.util.concurrent
    e.It doesn't exists till Java 8

  33. AtomicBoolean was introduced in which java version

  34. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8
    e.It doesn't exists till Java 8

  35. AtomicBoolean is a class/interface/abstract class/other?

  36. a.Class
    b.Interface
    c.Abstract class
    d.Other
    e.It doesn't exists till Java 8

  37. AtomicFloat is found in which package?

  38. a.java.util.concurrent.atomic
    b.java.util
    c.java.util.atomic
    d.java.util.concurrent
    e.It doesn't exists till Java 8

  39. AtomicFloat was introduced in which java version

  40. a.Java 5
    b.Java 6
    c.Java 7
    d.Java 8
    e.It doesn't exists till Java 8

  41. AtomicFloat is a class/interface/abstract class/other?

  42. a.Class
    b.Interface
    c.Abstract class
    d.Other
    e.It doesn't exists till Java 8

  43. Which is valid statement

  44. a.Callable interface provides method for computing and returning result
    b.submit() method is defined in ExecutorService interface and does not return result of computation.
    c.execute() method is defined in Executor interface.
    d.All



    Q23 - Q30, 8 HARD level difficulty questions 3 mark each.       3 * 8 = 24 marks

  45. Difference between java.util.concurrent.Callable and java.lang.Runnable

  46. a.Class implementing Callable interface must override call() method. call() method returns computed result or throws an exception if unable to do so.
    b.Class implementing Runnable interface must override run() method.
    c.A Runnable does not return a result and can neither throw a checked exception.
    d.All

  47. which of these class provide support for atomic operations till java 8?

  48. a.AtomicString
    b.AtomicDouble
    c.AtomicFloat
    d.AtomicBoolean

  49. What is maximum number of parties that could be registered with phaser at a time ?

  50. a.6500
    b.65535
    c.1500
    d.100

  51. What is java.util.concurrent.Exchanger class?

  52. a.Exchanger enables two methods to exchange their data between each other
    b.Exchanger enables remote method invocation RMI
    c.Exchanger enables two threads to exchange their data between each other
    d.

  53. What are key method of Lock interface?

  54. a.lock()/unLock() methods
    b.getLock()/ setLock() methods
    c.setLock()/getUnLock() methods
    d.None

  55. What will be output of following program -


  56. a.Thread-2 is Waiting to acquire lock Thread-1 is Waiting to acquire lock Thread-1 has acquired lock. Thread-2 didn't got lock.
    b.Thread-1 is Waiting to acquire lock Thread-2 is Waiting to acquire lock Thread-1 has acquired lock. Thread-2 didn't got lock.
    c.Thread-1 is Waiting to acquire lock Thread-1 has acquired lock. Thread-2 is Waiting to acquire lock Thread-2 didn't got lock.
    d.None

  57. What is valid about java.util.concurrent.CyclicBarrier?

  58. a.CyclicBarrier can't be used to trigger event
    b.CyclicBarrier can be awaited repeatedly
    c.CyclicBarrier can't be awaited repeatedly
    d.None

  59. What will be output of following code -


  60. a.parentPhaser isTerminated : true
            childPhaser isTerminated : true
           
            --childPhaser has called arriveAndDeregister()--
           
            parentPhaser isTerminated : false
            childPhaser isTerminated : true
    b.parentPhaser isTerminated : false
            childPhaser isTerminated : true
           
            --childPhaser has called arriveAndDeregister()--
           
            parentPhaser isTerminated : true
            childPhaser isTerminated : true
    c.parentPhaser isTerminated : false
            childPhaser isTerminated : false
           
            --childPhaser has called arriveAndDeregister()--
           
            parentPhaser isTerminated : true
            childPhaser isTerminated : true
    d.parentPhaser isTerminated : true
            childPhaser isTerminated : false
            --childPhaser has called arriveAndDeregister()--
            parentPhaser isTerminated : false
            childPhaser isTerminated : true




Quiz 3 - Correct answers



MEDIUM
1) c
2) a
3) a
4) a
5) d
6) d
7) a
8) a
9) a
10) a

11) a
12) a
13) e
14) e
15) e
16) a
17) a
18) a
19) e
20) e

21) e
22) d

HARD
23) d
24) d
25) b
26) c
27) a
28) b
29) b
30) c

1 comment: