Everything in a Java program not explicitly set to something by the programmer, is initialized to a zero value.
- For references (anything that holds an object) that is
- For int/short/byte/long that is a
- For float/double that is a
- For booleans that is a
- For char that is the null character
'\u0000'(whose decimal equivalent is 0).
When you create an array of something, all entries are also zeroed. So your array contains five zeros right after it is created by
Note (based on comments): The Java Virtual Machine is not required to zero out the underlying memory when allocating local variables (this allows efficient stack operations if needed) so to avoid random values the Java Language Specification requires local variables to be initialized.