Java Threading and Generics

Test your knowledge of Java multithreading concepts including thread states, synchronization, and race conditions, as well as Java generics including type parameters, raw types, and generic method declarations.

11 Questions Published

Questions

Question 1 Multiple Choice (Multiple Answers)

What are the benefits of generics?

  1. Generic collections accept only Object types
  2. Type errors are caught at compile time
  3. Generics result in readily understandable code
  4. Generics sometimes require type casting
Question 2 Multiple Choice (Multiple Answers)

What are the features of raw types?

  1. Can be used with Generic code
  2. Raw types take Type parameters
  3. Raw types must be cast to appropriate objects at runtime
  4. Type safety
Question 3 Multiple Choice (Single Answer)

Identify the type parameter which can be used to use all numeric types in a generic call.

  1. Integer
  2. Float
  3. Number
  4. Double
Question 4 Multiple Choice (Single Answer)

Which one is the superclass of all generic objects?

  1. <?>
  2. <Object>
  3. <? extends Object>
  4. None of these
Question 5 Multiple Choice (Single Answer)

To create a public generic method named "update" that has no return type. In its argument list, the method accepts an argument named "updateValue" which is of the same type as the type parameter - T. Which is a valid declaration?

  1. public T update()
  2. public void update(T updateValue)
  3. void update(T updateValue)
  4. public void update()
Question 6 Multiple Choice (Single Answer)

Will it run without error: Thread th = new Thread(new Thread());

  1. It will run without error
  2. Runtime Error
  3. Compilation Error
  4. None of all
Question 7 Multiple Choice (Single Answer)

What is true

  1. We can invoke run() method directly to start thread
  2. If we call start() method twice, two threads will be created
  3. t.sleep(50) - it will give minimum guarantee of at least 50ms this thread will not run
  4. Thread can be still alive even after the completion of run().
Question 8 Multiple Choice (Single Answer)

When you create a thread instance the state will be

  1. Ready
  2. Runnable
  3. New
  4. Waiting
Question 9 True/False

We can synchronize the variable to avoid race conditions.

  1. True
  2. False
Question 10 Multiple Choice (Single Answer)

If a thread goes to sleep in synchronized block. (Which one is false)

  1. it is still alive
  2. It will release all hold locks
  3. It comes to runnable state after sleep time expired
  4. No other thread can enter into the synchronized.
Question 11 True/False

Running thread can't come back to runnable state directly.

  1. True
  2. False