Java Syntax, Structure and Identifiers
Site Admin
· 11 Sep 2026
· 12 views
The Skeleton of a Java File
// package declaration (optional)
package demo;
// imports (optional)
import java.util.Scanner;
// class declaration
public class MyClass {
// fields and methods live inside the class
public static void main(String[] args) {
System.out.println("Java structure");
}
}Naming Rules for Identifiers
Identifiers are the names you give to classes, methods, variables and packages.
- May contain letters, digits, underscore (_) and dollar sign ($).
- Must begin with a letter, underscore or dollar sign (never a digit).
- Are case sensitive:
Totalandtotalare different names. - Cannot be a Java keyword such as
class,iforint.
Naming Conventions
- Classes: PascalCase, e.g.
BankAccount. - Methods and variables: camelCase, e.g.
getBalance,totalAmount. - Constants: UPPER_SNAKE_CASE, e.g.
MAX_RETRIES. - Packages: lowercase, e.g.
com.company.project.
Grammar Basics
- Statements end with a semicolon (
;). - Blocks of code are enclosed in curly braces
{ }. - Whitespace does not separate statements; it is only for readability.
- Java is case sensitive:
mainis not the same asMain.
Key Points
- A Java file is organised as package, imports, then one or more classes.
- Follow naming conventions so your code is readable and idiomatic.
- Semicolons close statements; braces group blocks.