Please enable JavaScript.
Coggle requires JavaScript to display documents.
Distinguishing Between Object References and Primitives (Number in code…
Distinguishing Between Object References and Primitives
Two data types
primitive types
8 primitive type
Doesn't need memorize size of type
reference types
Number in code
It is literal
e.g long max = 3123456789; //Does not compile
size of int is smaller than literal
correct: long max = 3123456789L;
L is type long.
can
lowercase l
Uppercase L
Convention uppercase
base format
decimal
e.g 20.
octal
017
hexadecimal
0xFF
can be x or X
binary
0b10
can be b or B
underscore is valid
valid literal numbers
int million1 = 1_000_000;
double annoyingButLegal = 1_00_0.0_0;
invalid literal numbers
double notAtStart =
1000.00;
double notAtEnd = 1000.00
;
double notByDecimal = 1000_.00;
Tips on exam
do not need convert number system
recognize valid literal values
Key Differences
Reference types
can
be null
call methods (points is not null)
cannot
begin uppercase
primitive types
cannot
be null //error compile
call methods
can
lowercase type name
Reference types
refers an object (instance of a class)
save a pointer
Not allow to learn physical memory
points to object