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

Suffixing a float literal with f or F or a long literal with l or L improves the clarity of the code, although it is not required. Primitive data types are passed by value, so changes made to the primitive's value inside a method are local to that method and are not retained after the method call completes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.15.94