Java's Numeric Literals

nullan as yet uncreated, or an invalid, Object Reference
true, falsethe two possible values of a boolean variable
29int constant - decimal representation
035int constant - octal (base 8) representation
0x1Dint constant - hexadecimal (base 16) representation

When an int constant (as above) is assigned to a byte variable or a short variable, it is automatically converted to byte or short as appropriate (provided its value lies within the valid range for that type).

29L     long constant - decimal representation
035L    long constant - octal (base 8) representation
0x1DL   long constant - hexadecimal (base 16) representation

18.0F   float constant - the .0 is optional, the F is mandatory
1.8E1F  float constant - exponent form, the F is mandatory
.18E2F  float constant - exponent form, the F is mandatory

18.0D   double constant - the .0 and the D are optional
1.8E1D  double constant - exponent form the D is optional
.18E2D  double constant - exponent form the D is optional
Zero can be positive or negative. These are numerically equal but give different results in certain calculations eg:

A non-float constant such as a double cannot be assigned to a float variable. You must use a float literal viz:

float x = 18.9F;

This page's parent within this Web Site. About this Web Site. Its home page. Email its Author.