0 votes
217 views
in Java by
What is the difference between runnable and callable in java?

1 Answer

0 votes
by (4.4k points)

The difference between runnable and callable in java is very important interview question. It is generally asked by interviewer.

See the following difference between runnable and callable:-

  • Callable is an interface which is added in java 5. So, Callable interface is newer than Runnable interface.
  • Runnable interface has run() method to perform some tasks while Callable interface has call() method to perform task.
  • run() method of Runnable interface does not return any value, It's return type is void. And call() method of Callable interface returns value. Callable interface is a generic parameterized interface and Type of value is provided, when instance of Callable implementation is created.
  • run() method can not throw checked exception, while call() method can throw checked exception.
  • public interface Runnable {
        void run();
    }

    public interface Callable<V> {
        V call() throws Exception;
    }

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...