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:
- Create a file named
HelloWorld.java
.
- Define a public class named
HelloWorld
.
- Inside the class, write the main method
main()
.
- Use
System.out.println()
to print the message "Hello World"
to the console.
- 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.
View Example Code
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.