Some Misc Notes
← prev | next →     Top-level ToC     /java/examples/primitive-data-types.html     (printable version)

1 Numbers

All integer types are signed and wrap around.

type 32-bit 64-bit
integer int long
real float double

By default, real literals are doubles (64-bit). If you want a float, you need to say so:

float  f = 1.2F;
double d = 1.2;

double d = 1.2F;  // Fine.
double d = 5;     // Fine.

By default, integer literals are ints (32-bit). If you want a long, you need to say so:

int  i = 42;
long j = 42L;

long i = 42;  // Fine.