Ask Your Question
3

What distinguishes the Java interfaces of Runnable and Callable from each other?

asked 2022-02-07 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-07-24 03:00:00 +0000

woof gravatar image

The Java interfaces of Runnable and Callable are both used to define a task that can be executed by a thread, but they have some differences:

  1. Return Value: The Runnable interface does not return any value, whereas the Callable interface allows the task to return a result.

  2. Exception Handling: The run() method of Runnable does not throw any checked exceptions, while the call() method of Callable throws checked exceptions.

  3. Implementation: The Runnable interface is implemented using the run() method, while the Callable interface is implemented using the call() method.

  4. Usage: Runnable is typically used for simple tasks that do not need to return any value, while Callable is used when a task requires a return value or when exceptions need to be handled explicitly.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-02-07 11:00:00 +0000

Seen: 11 times

Last updated: Jul 24 '21