7.1. The Java Value Type

The Java value type is also known as the primitive data type. Table 7.1 shows the Java primitives.

Variables can be declared as a primitive type. Depending on the scope where they are declared, they must be initialized. For example, you must initialize local method variables as shown here:

int age = 10;
long population = 100000L;
float price = 12.45f;
double count = 6.45d;
Table 7.1. Java Value Types (Primitives)
KeywordDescriptionSize/Format
ByteByte-length integer8 bits
ShortShort integer16 bits
IntInteger32 bits
LongLong integer64 bits
FloatSingle-precision floating point32-bit IEEE 754
DoubleDouble-precision floating point64-bit IEEE 754
CharA single character16-bit Unicode character
BooleanA Boolean valueTrue or false

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.