Loading lessons...
Java Syntax
Java Syntax
Every Java program is made of classes, and inside the classes you write statements that tell the computer what to do.
A minimal program
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Breaking it down
public class Maindeclares a class namedMain. A class is a container for code.public static void main(String[] args)is the entry point where the program starts.System.out.println("Hello World")prints text to the screen.- Every statement ends with a semicolon
;.
The main method
The main method must be written exactly like this or the program will not run:
public static void main(String[] args) {
// your code here
}
Curly braces
Curly braces { } mark the beginning and end of a block of code, such as a class or a method.
Case sensitivity
Java is case sensitive. System, system, and SYSTEM are three different names. Always match the exact spelling of keywords and method names.
TL;DR
- A Java program starts with a class and the
mainmethod. - Statements end with a semicolon.
System.out.println()prints text.- Curly braces group blocks of code.