+91 81900 98289

Java Syntax

A Java program is a class that contains methods. Statements end with a semicolon. Blocks of statements sit inside braces, and the usual style puts each nested block four spaces further in.

Java is case sensitive. System and system are different names. The file Hello.java must contain public class Hello, with the same spelling and the same capital letters.

Example

int seats stores a whole number. println can print a number without turning it into a string first.

public class Syntax { public static void main(String[] args) { int seats = 24; System.out.println(seats); } }
Missing a semicolon or a closing brace is a compile error. javac prints the line number. Fix that line and compile again.