Printing and PDF export are disabled for this content. View it online at Full Stack Learning Simplified.
Java Syntaxπ± Beginner
Java has a strict, consistent structure. A few rules apply to every program β once they're second nature, the rest of the language follows.
Program structure
Main.java
public class Main { // code lives in a class
public static void main(String[] args) { // execution starts here
System.out.println("Hello, world!"); // a statement
}
}- All code lives inside a class; the file name must match the public class name (
MainβMain.java). - Execution starts at
public static void main(String[] args). - Every statement ends with a semicolon
;. - Blocks are grouped with curly braces
{ }. - Java is case-sensitive:
Mainandmainare different.
Printing output
Main.java
System.out.println("with a newline");
System.out.print("no newline");
System.out.printf("Name: %s, Age: %d%n", "Asha", 30); // formattedComments
Main.java
// single-line comment
/* multi-line
comment */
/** Javadoc comment - documents a class or method */Packages & imports
Classes are organised into packages. You import classes from other packages to use them.
Main.java
package com.example.app; // declares the package (first line)
import java.util.List; // import a class to use itNaming conventions
| Element | Convention | Example |
|---|---|---|
| Class | PascalCase | BankAccount |
| Method / variable | camelCase | getBalance |
| Constant | UPPER_SNAKE | MAX_SIZE |
| Package | lowercase | com.example |
Tip: Whitespace and indentation don't affect how Java runs, but consistent formatting is expected β most teams let an IDE or formatter handle it automatically.
Java Key Takeaway: Exception handling separates checked (recoverable) from unchecked (runtime) exceptions. Prefer custom runtime exceptions for application business logic errors.
Free preview. Sign in and subscribe to unlock all 982 lessons across 31 courses.
Free preview Β· Β© 2026 Full Stack Learning Simplified