Variables & types in Java
How Java declares things: inferred with var, spelled out, or final.
// declarations: var infers from the right side, or you spell the type
var greeting = "hello, Java";
int year = 2026;
double ratio = 21.0 / 34;
boolean ready = year > 2000 && ratio < 1;
final String version = "21";
System.out.println(greeting + " (" + version + ")");
System.out.printf("ratio %.3f, ready: %b%n", ratio, ready);
How it works
varasks the compiler to infer the type from the right-hand side.int,doubleandbooleanspell the type when clarity wants it.finalmakes a binding permanent;printfformats the output.
Keywords and builtins used here
booleandoublefinalintvar
The run, in numbers
- Lines
- 9
- Characters to type
- 328
- Tokens
- 74
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 47 seconds.
Step 1 of 3 in Variables & types, step 1 of 29 in Language basics.