BeginnerLesson 1 of 16
Hello World, main & Running – Java
Structure of a Java program, output and comments.
Every Java program consists of classes. The entry point is the method main. With System.out.println you print a line.
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.print("Without a line break");
System.out.println();
System.out.printf("Number: %d, Text: %s%n", 42, "Java");
}
}Save this as Main.java and start it with java Main.java. There are three kinds of comments:
// Single-line comment
/* Multi-line
comment */
/** Javadoc: documents the following class or method. */TipIn the following lessons we often show only the contents of
main. You can type such lines directly into jshell or copy them into a main method.WarningJava is case-sensitive:
System is something different from system. Text goes in double quotes "...", single characters (char) in single quotes 'a'.