Core Java Syntax
Variables, types, control flow, and methods at a glance.
Primitive types
int i = 42;
whole numbersdouble d = 3.14;
decimalsboolean b = true;
true / falsechar c = 'A';
one characterlong / short / byte / float
sized variants
Operators
+ - * / %
arithmetic (% = remainder)== != > < >= <=
comparison → boolean&& || !
logical and / or / not= += -= ++ --
assignment
Control flow
if (x > 0) { … } else { … }switch (day) { case 1 -> "Mon"; default -> "?"; }for (int i = 0; i < n; i++) { … }while (cond) { … }for (String s : list) { … }for-each
Methods
int add(int a, int b) { return a + b; }void greet() { … }returns nothingstatic int square(int n) { return n * n; }
The program skeleton
public class App { public static void main(String[] args) { System.out.println("Hello"); } }