Java thread Programming - Create a Basic Thread to Print "Hello, World!"

Java Thread: Exercise-1 with Solution

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 {
  public void run() {
    System.out.println("Hello, World!");
  public static void main(String[] args) {
    Hello_world_thread thread = new Hello_world_thread();

Sample Output:

Hello, World!

Java Thread Exercises: Hello World Thread


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: Java Thread  Exercises - Create a Basic Thread to Print 'Hello, World!'

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.

Follow us on Facebook and Twitter for latest update.