DEV Community

Gowtham Kalyan
Gowtham Kalyan

Posted on

Ways to Create a Thread in Java – Complete Guide for Beginners

Multithreading is one of the most powerful features of Java that allows a program to execute multiple tasks simultaneously. A thread is a lightweight unit of execution inside a process, helping applications perform faster and utilize system resources efficiently. Understanding how to create threads in Java is very important for real-time application development and technical interviews.

In Java, threads are mainly created using two standard approaches.


1️⃣ Creating a Thread by Extending the Thread Class

One simple way to create a thread is by extending the Thread class. You need to override the run() method, which contains the task that the thread will execute.

class MyThread extends Thread {
    public void run() {
        System.out.println("Thread created using Thread class");
    }
}

public class Test {
    public static void main(String[] args) {
        MyThread t = new MyThread();
        t.start();
    }
}
Enter fullscreen mode Exit fullscreen mode

When start() is called, a new thread is created and the run() method executes independently.

Limitation: Since Java does not support multiple inheritance, extending Thread prevents your class from extending any other class.


2️⃣ Creating a Thread by Implementing Runnable Interface (Recommended)

The most commonly used method is implementing the Runnable interface.

class MyRunnable implements Runnable {
    public void run() {
        System.out.println("Thread created using Runnable interface");
    }
}

public class Test {
    public static void main(String[] args) {
        Thread t = new Thread(new MyRunnable());
        t.start();
    }
}
Enter fullscreen mode Exit fullscreen mode

Advantages:

  • Allows multiple inheritance through interfaces
  • Better code reusability
  • Preferred in real-time projects

3️⃣ Using Lambda Expression (Java 8+)

Modern Java provides a shorter way using lambda expressions.

public class Test {
    public static void main(String[] args) {
        Thread t = new Thread(() ->
            System.out.println("Thread using Lambda expression")
        );
        t.start();
    }
}
Enter fullscreen mode Exit fullscreen mode

This approach reduces boilerplate code and is widely used in modern applications.


✅ When to Use Which Method?

  • Use Thread class for simple demonstrations.
  • Use Runnable for scalable and professional applications.
  • Use Lambda expressions for clean and modern coding style.

🚀 Conclusion

Multithreading plays a key role in building high-performance Java applications such as web servers, banking systems, and enterprise software. Learning thread creation techniques helps developers understand concurrency, improve application speed, and prepare for real-time development scenarios.


🔥 Promotional Content

If you want to master Java concepts with practical implementation, real industry scenarios, and hands-on coding, join the Top Java Real Time Projects Online Training in 2026. This program focuses on live projects, interview preparation, and real-time development experience.
Build strong Java skills and become job-ready with real-time project exposure.

Top comments (0)