Variables come in two flawors:
- Primitives
- Reference
Primitives
Primitives hold fundamental values (think: simple bit patterns)
Bool and char
boolean = (JVM-specific)| true / falseboolean fun = true;
char = 16bits | 0 to 65535char c = 'g';
Numeric – integer
byte = 8 bits | -128 to 127byte b = 89;
short = 16 bits | -32768 to 32767short s = 10;
int = 32 bits | -2147483648 to -2147483648 int i = 300;
long = 64 bits | huge to hugelong L = 3498989;
Floating points
float = 32 bits | variesfloat f = 32.4f;
(Note the ‘f’. Gotta have that with a float, because Java thinks anything with a floating point is a double, unless you use ‘f’)
double = 64 bits | variesdouble d = 3222.77;
References
References are names. Objects are stuff. You can have different names for stuff, even for stuff that doesn’t actually exist.
You can declare names, without actually giving them any “real” meaning, like this:
Employee emp = new Employee();
emp = a reference