Why do double instance variables in java have a lower case d attached to them? Do they need to have this?
Example:
double area = 0d;
double avgDailyTemp = 26d;
etc...
Why do double instance variables in java have a lower case d attached to them? Do they need to have this?
Example:
double area = 0d;
double avgDailyTemp = 26d;
etc...
A number literal by default is an integer. If you attempt to pass a number like ten billion into Java double it'll error since it's outside the bounds of an integer. Specifying the lowercase d
explicitly defines it as a double literal instead.
double a = 10000000000; // ERROR! Integer number too large
double b = 10000000000d; // OK!
It is not the variable which requires the d
, but the constant value declared. It is a "hint" to the compiler of the data type.
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html