What primitive types does Java have? What are the default values of variables and array elements?
Short answer
Java has 8 primitive types (types that store the value directly): byte, short, int, long, float, double, char, boolean. Fields and arrays get default values, local variables do not.
3 points to say:
Stringis not a primitive, it is a class.- Fields default to
0,false,null; locals must be assigned before reading. - IDs and timestamps use
long, becauseintoverflows around 2.1 billion.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.