Java as a typed language: Integer, Floating point, Character, Boolean type

Java is a typed language. Every variable, expression, assignments, and parameters has a strict defined type. Type conversions are not automatic in Java. Type checking is what that differentiates Java from C and C++.

Integer: Integer type in Java could be int, byte, short, and long. Values of these types are signed, positive and negative values. Java doesn’t define any unsigned integers.

int: int is a signed 32-bit type. It has a range from –2,147,483,648 to 2,147,483,647. It is commonly used for controlling loops and indexing arrays.

byte: byte is a signed 8-bit type. It has a range from –128 to 127. It is commonly used for streams and binary data.

short: short is a signed 16-bit type. It has a range from –32,768 to 32,767.

long: long is a signed 64-bit type. It has a range from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

Floating point type: It is used for fractions.

float: It is a single precision with size 32 bits. It’s range is 4.9e–324 to 1.8e+308.

double: It is a double precision with size 64 bits. It’s range is 1.4e−045 to 3.4e+038.

Character type: In Java, unicode is used for characters for portability. char is a 16 bit type. The range of a char is 0 to 65,536.

Boolean type: Boolean is used for logical value, either true or false.

Leave a Reply