Basic Syntax

This exercise introduces you to the basic structure of a Java program. By writing a program that prints the message "Hello World," you'll learn how to work with the main method public static void main(String[] args) and how to use System.out.println() to display text to the console.

This is an important first step in understanding how a Java program executes and how it interacts with the user through console output.

Topic

Java Fundamentals

Java Exercise

In this exercise, you will create a Java program that prints the message "Hello World" to the console. This is the first step to learning Java Basic Syntax and familiarizing yourself with its fundamental structure.

Exercise Objectives:

  • Understand the basic structure of a Java program.
  • Learn how to define the main method public static void main(String[] args).
  • Use System.out.println() to display text to the console.

Instructions:

  1. Create a file named HelloWorld.java.
  2. Define a public class named HelloWorld.
  3. Inside the class, write the main method main().
  4. Use System.out.println() to print the message "Hello World" to the console.
  5. Compile and run the program to see the output.

This exercise will help you get started with Java programming and understand how Java programs run.


public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

 Output:

Hello World

This program demonstrates a simple Java application that outputs the phrase **"Hello World"** to the console. It is a basic example that illustrates how to use the **System.out.println** method to print a string. This program serves as a starting point for learning Java and understanding how to run a Java program that outputs text to the console. The code is concise and highlights the fundamental structure of a Java program, including the **main method** that serves as the entry point of execution.


 Share this JAVA exercise