Java Syntax
Java is picky about syntax. Each statement ends with a semicolon, blocks use curly braces { }, and names are case-sensitive: Main and main are different.
ExampleJava
public class Main {
public static void main(String[] args) {
// This is a single-line comment
System.out.println("First line");
/* This is a
multi-line comment */
System.out.println("Second line");
}
}Output
First line Second line
By convention class names start with a capital letter (MyClass), while methods and variables start lower case (myMethod). The file name must match the public class name: Main lives in Main.java.
Quick check
How does a Java statement end?
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.