Java Syntax References

Java syntax quick reference: variables, loops, collections, classes and exceptions, from Oracle's official dev.java docs. Every item below is clearly marked as a shortcut, command, or syntax reference.

Most Useful Java Syntax References

JavaSyntax

Main Method

Code example
public static void main(String[] args) { ... }

The entry point of a Java program.

Learn More
JavaSyntax

Print to Console

Code example
System.out.println("Hello");

Prints a line to standard output.

Learn More
JavaSyntax

Declare a Variable

Code example
int count = 0; String name = "Ada";

Declares a typed variable.

Learn More
JavaSyntax

If / Else

Code example
if (x > 0) { ... } else if (x == 0) { ... } else { ... }

Runs code depending on a condition.

Learn More
JavaSyntax

For Loop

Code example
for (int i = 0; i < 10; i++) { ... }

Loops a set number of times.

Learn More
JavaSyntax

For-Each Loop

Code example
for (String item : items) { ... }

Loops over every item in an array or collection.

Learn More
JavaSyntax

Create an Array

Code example
int[] nums = {1, 2, 3}; int[] empty = new int[5];

Creates a fixed-size array.

Learn More
JavaSyntax

Create a List

Code example
List<String> names = new ArrayList<>();

Creates a resizable list.

Learn More

More Java Syntax References

Frequently Asked Questions

What does this Java syntax reference cover?

It covers 40 common Java patterns and examples, including Main Method, Print to Console, Declare a Variable, If / Else, For Loop.

Can I copy the Java examples?

Yes. Each reference page includes a copyable code example.

What affects these Java examples?

Check the linked documentation for language or runtime version requirements. Libraries, file paths, terminal quoting and environment settings can differ across systems; no blanket platform compatibility is implied.