Lesson content
Read, practise, then check your understanding
Java primitives are boolean, byte, short, int, long, char, float, and double. Reference variables point to objects or hold null. Fields receive default values; local variables must be definitely assigned before reading. Prefer the smallest domain-appropriate type, not merely the smallest storage width.
Values and expressions
final int secondsPerHour = 60 * 60;
long population = 1_428_000_000L;
double ratio = 5.0 / 8.0;
char grade = 'A';
String label = "Java";
boolean valid = population > 0 && label != null;
Arithmetic includes + - * / %; integer division truncates. Relational operators yield booleans. && and || short-circuit, while & | ^ ~ << >> >>> also operate on bits. Numeric promotion may widen operands; narrowing needs an explicit cast and can lose data. Integer overflow wraps in two’s-complement arithmetic, so use Math.addExact when overflow is an error. == compares primitive values but reference identity; object value equality normally uses equals.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.