Java basics
The structure of a Java program, printing and input, variables and types, and decisions and loops.
About 5 hours of study
Learning objectives
- Write and run a complete program
- Choose the right types
- Control flow with if, switch and loops
Lessons
- 1
Your first Java program
How a Java program is laid out, how javac and the JVM turn it into a running program, printing with println, print and printf, and reading input with Scanner.
- 2
Variables and types
Java's primitive types, int and long, double, char and boolean, String, declaring variables with types or var, constants with final, casts, integer division, and overflow.
- 3
Decisions and loops
if, else if and else, comparison and logical operators, the switch statement and the newer switch expression, and for, while, do-while and enhanced for loops with break and continue.
Module practice
- Java: Greet a visitorEasy
- Java: Measure a rectangleMedium
- Java: Print an aligned receiptHard
- Java: Convert a temperatureEasy
- Java: Split seconds into days and hoursMedium
- Java: Detect int overflowHard
- Java: List the leap yearsEasy
- Java: Replay a guessing gameMedium
- Java: Draw a diamond of starsHard