Introduction to Java CompletableFuture & Asynchronous Programming
A beginner-level quiz on Java's CompletableFuture and asynchronous programming concepts.
Questions in this quiz
15 questions on Introduction to Java CompletableFuture & Asynchronous Programming. Work through them here, then start the quiz to answer them and see your score.
1.What is the primary purpose of CompletableFuture in Java?
- ATo perform asynchronous computations
- BTo handle synchronous operations
- CTo create user interfaces
- DTo manage database connections
2.Which method is used to create a completed CompletableFuture with a given value?
- ArunAsync()
- BcompletedFuture()
- Ccomplete()
- DsupplyAsync()
3.What does the CompletableFuture.supplyAsync() method do?
- AExecutes a Runnable task asynchronously
- BExecutes a Supplier task asynchronously
- CCompletes a CompletableFuture with a value
- DCancels an asynchronous task
4.Which method can be used to handle exceptions in a CompletableFuture?
- Ahandle()
- BthenApply()
- CcompleteExceptionally()
- DthenRun()
5.What does the thenApply() method do in a CompletableFuture?
- ACombines two CompletableFutures
- BExecutes a task without returning a result
- CHandles exceptions
- DTransforms the result of a CompletableFuture
6.Which method combines two CompletableFutures and executes a task when both are complete?
- AallOf()
- BthenAcceptBoth()
- CthenCombine()
- DthenCompose()
7.What is the purpose of the CompletableFuture.allOf() method?
- ATo execute a task asynchronously
- BTo complete a CompletableFuture with a value
- CTo wait for all provided CompletableFutures to complete
- DTo handle exceptions in a CompletableFuture
8.Which method is used to execute a Runnable task asynchronously with CompletableFuture?
- AsupplyAsync()
- BthenRun()
- CthenAccept()
- DrunAsync()
9.What does the method thenAccept() do in a CompletableFuture?
- ACombines two CompletableFutures
- BExecutes a Supplier task asynchronously
- CExecutes a Consumer on the result of a CompletableFuture
- DHandles exceptions
10.Which method allows chaining of CompletableFutures where the next stage depends on the result of the previous?
- AthenApply()
- BthenCombine()
- CthenCompose()
- Dhandle()
11.What is the default executor used by CompletableFuture for asynchronous tasks?
- ASingleThreadExecutor
- BExecutors.newCachedThreadPool()
- CExecutors.newFixedThreadPool()
- DForkJoinPool.commonPool()
12.Which method is used to manually complete a CompletableFuture?
- AthenApply()
- BsupplyAsync()
- Ccomplete()
- DcompleteExceptionally()
13.What does the method exceptionally() do in a CompletableFuture?
- ACombines two CompletableFutures
- BHandles exceptions and provides an alternative result
- CExecutes a task asynchronously
- DTransforms the result of a CompletableFuture
14.Which method would you use to execute a task after a CompletableFuture completes, regardless of its outcome?
- AthenCombine()
- Bhandle()
- CthenApply()
- DwhenComplete()
15.What is the return type of CompletableFuture.get() method?
- AAn exception
- BA CompletableFuture
- CThe result of the computation
- DA boolean indicating completion