Index:
Java “Hello, World!” Program
Output: Hello, World!
How does it work?
-
// Your First Program
- In Java, any line starting with
//
is a comment.
- In Java, any line starting with
-
class HelloWorld { ... }
-
In Java, every application begins with a class definition. In the program, HelloWorld is the name of the class.
-
For now, just remember that every Java application has a class definition, and the name of the class should match the filename in Java.
-
-
public static void main(String[] args) { ... }
-
This is the main method. Every application in Java must contain the main method. The Java compiler starts executing the code from the main method.
-
For now, just remember that the main function is the entry point of your Java application, and it’s mandatory in a Java program.
-
-
System.out.println("Hello, World!");
-
The code above is a print statement. It prints the text
Hello, World!
to standard output (your screen). The text inside the quotation marks is called Java Strings. -
Notice the print statement is inside the main function, which is inside the class definition.
-