QuizzesAdvanced Java Concurrency: Mastering CompletableFuture vs. Future
advanced
java

Advanced Java Concurrency: Mastering CompletableFuture vs. Future

Assess your understanding of advanced concurrency patterns in Java using CompletableFuture and Future.

20 minutes 10 questions Pass at 70%
Time Limit
20 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

10 questions on Advanced Java Concurrency: Mastering CompletableFuture vs. Future. Work through them here, then start the quiz to answer them and see your score.

  1. 1.What is a key advantage of CompletableFuture over Future in Java?

    • ACompletableFuture can be completed manually.
    • BCompletableFuture is part of the java.util.concurrent package.
    • CCompletableFuture does not support asynchronous execution.
    • DCompletableFuture blocks the thread until the result is available.
  2. 2.Which method in CompletableFuture allows combining two futures when both are complete?

    • AthenCombine()
    • BthenRun()
    • CthenApply()
    • DthenAccept()
  3. 3.How does CompletableFuture handle exceptions compared to Future?

    • ACompletableFuture cannot handle exceptions.
    • BCompletableFuture throws exceptions directly.
    • CCompletableFuture uses catch() to handle exceptions.
    • DCompletableFuture uses exceptionally() to handle exceptions.
  4. 4.Which CompletableFuture method is used to execute a task asynchronously without returning a result?

    • AthenComposeAsync()
    • BsupplyAsync()
    • CthenApplyAsync()
    • DrunAsync()
  5. 5.What is the purpose of the CompletableFuture method thenCompose()?

    • ATo execute a task without returning a result.
    • BTo chain dependent futures.
    • CTo handle exceptions.
    • DTo combine results of two independent futures.
  6. 6.In what scenario would you prefer using Future over CompletableFuture?

    • AWhen you want to chain multiple asynchronous tasks.
    • BWhen you need simple blocking calls.
    • CWhen you need manual completion of tasks.
    • DWhen you need to handle exceptions asynchronously.
  7. 7.Which method in CompletableFuture allows setting a default value if the computation fails?

    • Ahandle()
    • Bexceptionally()
    • CcompleteExceptionally()
    • DthenApply()
  8. 8.What is the result of calling get() on a CompletableFuture that has not yet completed?

    • AIt blocks until the result is available.
    • BIt returns an empty Optional.
    • CIt returns null.
    • DIt throws an exception immediately.
  9. 9.How can you execute a CompletableFuture task on a custom executor?

    • ABy setting the executor globally.
    • BBy using the thenApplyAsync() method.
    • CBy using a static method in CompletableFuture.
    • DBy passing the executor to supplyAsync() or runAsync().
  10. 10.Which CompletableFuture method allows you to perform an action after a future completes, regardless of its outcome?

    • AthenCombine()
    • BthenAccept()
    • CthenApply()
    • DwhenComplete()