Mastering Java Concurrency: CompletableFuture & Async Programming
Test your knowledge on Java's CompletableFuture and asynchronous programming techniques.
Questions in this quiz
12 questions on Mastering Java Concurrency: CompletableFuture & Async Programming. Work through them here, then start the quiz to answer them and see your score.
1.What is the primary advantage of using CompletableFuture over Future in Java?
- ACompletableFuture is part of Java 7.
- BCompletableFuture blocks the calling thread.
- CCompletableFuture can be completed manually.
- DCompletableFuture does not support chaining operations.
2.Which method in CompletableFuture is used to run a task asynchronously without returning a result?
- AthenApply()
- BrunAsync()
- CthenAccept()
- DsupplyAsync()
3.How can you handle exceptions in a CompletableFuture chain?
- AUsing exceptionally()
- BBoth A and B
- CUsing thenApply()
- DUsing handle()
4.What does the method thenCombine() do in CompletableFuture?
- ACombines two CompletableFutures sequentially.
- BCombines two CompletableFutures in parallel.
- CCombines the result of two CompletableFutures.
- DCombines two CompletableFutures into a single Future.
5.Which method allows you to execute a task after both CompletableFutures are complete?
- AthenAcceptBoth()
- BthenCombine()
- CthenRun()
- DthenCompose()
6.What is the role of the ForkJoinPool in CompletableFuture?
- AIt provides a common pool for parallel execution.
- BIt is used to block threads.
- CIt is used to synchronize threads.
- DIt is used to manage I/O operations.
7.Which method in CompletableFuture is used to transform the result of a computation?
- AthenCombine()
- BthenAccept()
- CthenApply()
- DthenRun()
8.What is the default behavior of CompletableFuture when no Executor is provided?
- ARuns tasks sequentially.
- BThrows an exception.
- CUses the common ForkJoinPool.
- DUses a single-threaded executor.
9.How can you wait for multiple CompletableFutures to complete before proceeding?
- AUsing join()
- BUsing thenRun()
- CUsing anyOf()
- DUsing allOf()
10.What does the method thenCompose() do in CompletableFuture?
- ACombines two CompletableFutures.
- BChains another CompletableFuture dependent on the first.
- CHandles exceptions in the CompletableFuture chain.
- DExecutes a task after both CompletableFutures complete.
11.Which method in CompletableFuture can be used to execute a task after the completion of another CompletableFuture, regardless of its outcome?
- AthenApply()
- BthenCombine()
- Chandle()
- DwhenComplete()
12.What is the purpose of the supplyAsync() method in CompletableFuture?
- ATo run a task synchronously that returns a result.
- BTo run a task asynchronously that returns a result.
- CTo run a task asynchronously without returning a result.
- DTo combine results of multiple CompletableFutures.