Java thread Programming - Create a Basic Thread to Print "Hello, World!"
Write a Java program to create a basic Java thread that prints "Hello, World!" when executed.
Sample Solution:
Java Code:
public class Hello_world_thread extends Thread {
@Override
public void run() {
System.out.println("Hello, World!");
}
public static void main(String[] args) {
Hello_world_thread thread = new Hello_world_thread();
thread.start();
}
}
Sample Output:
Hello, World!
Explanation:
In the above exercise,
In the main method, an instance of the Hello_world_thread class is created, and the start() method is called on that instance. This starts the thread's execution, which invokes the over ridden run() method.
When the program is executed, it creates another thread and runs it, causing "Hello, World!" to be printed to the console.
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Java program to create a thread that prints "Hello, World!" repeatedly for 10 iterations with a one-second delay using Thread.sleep().
- Write a Java program to implement a thread by overriding the Thread class that prints "Hello, World!" along with the thread's name.
- Write a Java program to create a thread using a lambda expression that prints "Hello, World!" and then terminates.
- Write a Java program to create a thread that prints "Hello, World!" and logs its thread ID and priority.
Java Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Java Thread Exercises Home.
Next: Find and Print Even-Odd Numbers with Threads.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics