Hello World
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Types
- Primitives:
int
, long
, double
, float
, boolean
, char
, byte
, short
.
- Reference types:
String
, arrays, classes, interfaces, enums, records.
Control Flow
int n = 5;
if (n > 3) System.out.println("big");
else System.out.println("small");
for (int i = 0; i < 3; i++) System.out.println(i);
switch (n) {
case 1 -> System.out.println("one");
case 2 -> System.out.println("two");
default -> System.out.println("other");
}