What is a thread in Java, and how do you create one?

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.

Key Points

Why Do We Need Threads?

Without threads

With threads

Example

A banking application can

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();
    }
}

Output

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();
    }
}

Output

Task executed by thread

Why Runnable Is Preferred?

Implementing Runnable is generally preferred because

Thread Lifecycle

A thread typically moves through the following states

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.

Real-World Example

Consider a food delivery application.

Thread 1

Thread 2

Thread 3

All tasks can run concurrently without waiting for each other.

Benefits of Multithreading

Common Uses of Threads

Interview Tip

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?

More Core Java - Level II interview questions

All Core Java - Level II questions