A thread is the smallest unit of execution within a Java program. It allows multiple tasks to run concurrently, enabling better utilization of system resources and improved application responsiveness. Java provides built-in support for multithreading, making it easier to perform multiple operations simultaneously.
Why Do We Need Threads?
at the same time using multiple threads.
Method 1: Extending the Thread Class
A class can create a thread by extending the Thread class and overriding the run() method.
class MyThread extends Thread {
@Override
public void run() {
System.out.println(
"Thread is running");
}
}
public class Demo {
public static void main(String[] args) {
MyThread thread =
new MyThread();
thread.start();
}
}Thread is running
Method 2: Implementing the Runnable Interface
A class can implement Runnable and provide the task inside the run() method.
class MyTask implements Runnable {
@Override
public void run() {
System.out.println(
"Task executed by thread");
}
}
public class Demo {
public static void main(String[] args) {
Thread thread =
new Thread(
new MyTask());
thread.start();
}
}Task executed by thread
Why Runnable Is Preferred?
Thread Lifecycle
1. New
Thread object is created.
2. Runnable
Thread is ready to run.
3. Running
Thread is actively executing.
4. Blocked / Waiting
Thread waits for a resource or event.
5. Terminated
Thread completes execution.
Consider a food delivery application.
All tasks can run concurrently without waiting for each other.
Benefits of Multithreading
Common Uses of Threads
A concise interview answer is
A thread is an independent path of execution within a Java program that enables concurrent task processing. Threads can be created either by extending the Thread class or by implementing the Runnable interface. Among the two approaches, implementing Runnable is generally preferred because it provides greater flexibility and supports better object-oriented design.
Last updated: 11 November 2026
Previous question: What are the SOLID principles?
Next question: Can you explain the lifecycle of a Java thread?