Java Thread Safety & Concurrent Collections: Intermediate Concepts
Assess your understanding of Java's thread safety mechanisms and concurrent collections.
Questions in this quiz
12 questions on Java Thread Safety & Concurrent Collections: Intermediate Concepts. Work through them here, then start the quiz to answer them and see your score.
1.Which of the following collections is thread-safe by default in Java?
- AArrayList
- BHashSet
- CLinkedList
- DVector
2.What is the primary advantage of using ConcurrentHashMap over Hashtable?
- AHigher memory usage
- BSynchronized on whole map
- CSupports null keys
- DFaster read operations
3.In Java, which class would you use for a thread-safe, ordered collection?
- ATreeSet
- BLinkedHashSet
- CConcurrentSkipListSet
- DCopyOnWriteArrayList
4.What is the main purpose of the 'synchronized' keyword in Java?
- ATo ensure thread safety
- BTo speed up execution
- CTo handle exceptions
- DTo manage memory
5.Which method in the ReentrantLock class is used to check if the lock is held by any thread?
- AisLocked()
- Block()
- CisHeldByCurrentThread()
- DtryLock()
6.What is the main difference between synchronized blocks and synchronized methods?
- ASynchronized methods are more flexible
- BSynchronized methods lock the entire object
- CSynchronized blocks are deprecated
- DSynchronized blocks are faster
7.Which of the following is a non-blocking alternative to synchronized collections?
- AHashSet
- BArrayList
- CLinkedList
- DCopyOnWriteArrayList
8.Why would you use a ReadWriteLock over a synchronized block?
- ATo allow multiple readers
- BTo reduce memory usage
- CTo increase write speed
- DTo simplify code
9.Which class provides atomic operations on single variables?
- AAtomicInteger
- BAtomicMap
- CAtomicList
- DInteger
10.What does the method 'computeIfAbsent' in ConcurrentHashMap do?
- ARemoves a mapping if absent
- BClears the map
- CComputes a value if absent
- DReplaces a value if present
11.Which of the following is true about the BlockingQueue interface?
- AIt allows null elements
- BIt is a subclass of List
- CIt supports operations that wait for space or elements
- DIt is not thread-safe
12.What is the main advantage of using a ConcurrentLinkedQueue?
- AIt allows null elements
- BIt is a lock-free, thread-safe queue
- CIt maintains insertion order
- DIt is faster than ArrayList