Java Syntax
Java syntax defines rules for writing valid programs: statements end with semicolons, code blocks are wrapped in curly braces, and everything (variables, methods) lives inside classes.
Java is case-sensitive, so `total` and `Total` are different identifiers. Class names conventionally start with an uppercase letter, while variables and methods use camelCase.
public class Main {
statement1;
statement2;
}Statements and blocks
Each instruction ends with a semicolon. Related statements are grouped into a block using curly braces, such as the body of a method or if statement.
Naming conventions
Classes use PascalCase (MyClass), while variables and methods use camelCase (myVariable). Constants use UPPER_SNAKE_CASE.
public class Main {
public static void main(String[] args) {
int age = 25;
System.out.println("Age: " + age);
}
}Age: 25A block is enclosed in braces, and each statement ends with a semicolon.
Key points
- Statements end with a semicolon.
- Curly braces group statements into blocks.
- Java is case-sensitive.
- Class names use PascalCase; variables use camelCase.
