Callable and Future
All Java Topics
Last updated: May 25, 2026
Author: ManaCoding Team
Callable and Future in Java are used for executing tasks in threads that return a result and can throw exceptions. They are commonly used with Executor Framework.
Syntax
import java.util.concurrent.*; Callable<Integer> task = () -> 10 + 20; Future<Integer> result = executor.submit(task);
Example Program
import java.util.concurrent.*;
class MyTask implements Callable<Integer> {
public Integer call() {
return 5 * 5;
}
}
public class Main {
public static void main(String[] args) throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(1);
Callable<Integer> task = new MyTask();
Future<Integer> future = executor.submit(task);
System.out.println("Task submitted...");
Integer result = future.get();
System.out.println("Result: " + result);
executor.shutdown();
}
}
// Output:
// Task submitted...
// Result: 25
What is Callable?
- 1 Functional interface similar to Runnable.
- 2 Returns a result using call() method.
- 3 Can throw checked exceptions.
- 4 Used with ExecutorService.
What is Future?
- 1 Represents result of async computation.
- 2 Used to retrieve value from Callable.
- 3 Provides methods like get(), cancel().
- 4 Supports asynchronous programming.
Callable vs Runnable
- 1 Callable returns result.
- 2 Runnable does not return result.
- 3 Callable can throw exceptions.
- 4 Runnable is simpler.
Why Use Callable & Future?
- 1 To get results from threads.
- 2 To perform async computations.
- 3 To improve performance.
- 4 To handle complex tasks.
Quick Summary
- Callable returns a result from thread execution.
- Future stores the result of async task.
- Used with ExecutorService.
- Supports asynchronous programming.
FAQs
What is Callable in Java?
It is a task that returns a result and can throw exceptions.
What is Future?
It represents the result of an asynchronous computation.
Difference between Runnable and Callable?
Runnable does not return value, Callable returns value.
What does Future.get() do?
It retrieves the result of computation, blocking if needed.
Which framework is used with Callable?
Executor Framework.
Interview Questions
Q1.
What is Callable in Java?
Answer:
It is a task that returns a result and can throw exceptions.
Q2.
What is Future?
Answer:
It represents the result of an asynchronous computation.
Q3.
Difference between Runnable and Callable?
Answer:
Runnable does not return value, Callable returns value.
Q4.
What does Future.get() do?
Answer:
It retrieves the result of computation, blocking if needed.
Q5.
Which framework is used with Callable?
Answer:
Executor Framework.
Quiz
Which interface returns a result in Java concurrency?