01 — Data types & variables
Overview
- Primitive types:
int,double,boolean,char,long,short,byte,float. - Reference types:
String, arrays, and objects (instances of classes). - Variables hold values; each variable has a type that determines what it can store.
- Use
finalfor constants.
Common gotchas
Stringis immutable.- Numeric literal types: add
Lfor long,ffor float. - Integer division truncates (e.g.,
3/2 == 1). Use3.0/2for floating division.
Example: DatatypesExample.java
- Demonstrates declarations, assignment, constants, and type conversion.