5 Difference between Callable and Runnable in Java

There is a lot of similarity between callable and runnable in java. But there are certain tasks callable can do while runnable can not.When designing a concurrent thread people often ask why to choose one over another.In this post we will discuss the difference between callable and runnable in java.

Difference between Callable and Runnable in Java

1. Checked Exception : Callable's call() method can throw checked exception while  Runnable run() method can  not throw checked exception.

2. Return value : Return type of Runnable run() method is void , so it can not return any value.
while Callable can return the Future object, which represents the life cycle of a task and provides methods to check if the task has been completed or canceled.
3. Implementation : Callable needs to implement call() method while Runnable needs to implement run() method.

public interface Runnable {
    void run();
public interface Callable<V> {
    V call() throws Exception;

How to Reverse an int Array in Java with Example

There are multiple ways we can perform how to reverse an array in java with example. Reversing an array is an easy question. Let understand the question through the example :

Input    : {3, 8, 5, 7, 4}
Output : {4, 7, 5, 8, 3}

Input     : {10, 54, 23, 89, 97, 2}
Output  : {2, 97, 89, 23, 54, 10}

Read Also :   How to reverse a string in java with Example

Pseudo Code for Reverse Array in Java Method 1:

1. Swap the values of left indices with the right indices till the mid element.