Wednesday, March 30, 2011

Java default values

There is a simple rule - when you define a member variable, it gets a default value. When you define local value, it do not get any default value - it has to be inicialized before the first use, or an compile-time exception will be thrown.

Default values for member variables:

Data Type Default Value (for fields)
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char '\u0000'
Any object null
boolean false

No comments:

Post a Comment