I'm going to give a pretty vanilla answer.
By default, a literal number in Java is interpreted as an int
. For instance, 123
is always going to be an int
.
By default, a floating-point decimal number in Java is interpreted as a double
. For instance, 123.45
is always going to be a double
.
You can add L
to the end of a number to create a long
, or f
at the end of a decimal number to create a float
.
There are a myriad of other numeral containers that can do numbers higher than the limits of either a 32 or a 64-bit signed number, or that can hold more precision than a 64-bit double (such as BigInteger
and BigDecimal
), so the correct answer to if it's primarily used is that it really depends on what it is you're doing.
Java has its defaults, but you don't have to stick to them.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…