Java Introduction: Your First Hello World Program

Java · Lesson 2 of 22

Every Java program starts from a class and a main method. The first program below prints a message on the screen.

  • class HelloWorld declares a class named HelloWorld.
  • public static void main(String args[]) is where the program starts running.
  • System.out.println("Hello World"); prints the text and moves to a new line.

Save the file as HelloWorld.java, compile it with javac HelloWorld.java and run it with java HelloWorld.

Unit - 1 HelloWorld Example - Source code

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

Unit - 1 HelloWorld Output:

Unit-1 Java Introduction illustration

Test what you learned

1 free Java test with instant scores.

Take a Java test

More Java lessons

Learn it in a course

WhatsApp us