Every variable has a type, every expression has a type and all types are strictly define moreover every assignment should be checked by the compiler by the type compatibility hence java language is considered as strongly typed programming language.
byte:
Size: 1 byte (8 bits)Range: -128 to 127
byte data type is best suitable if we are handling data in terms of streams either from the file or from the network.
short:The most rarely used data type in Java is short.
Size: 2 byteRange: -32768 to 32767
short data type is best suitable for 16-bit processors like 8086 but these processors are completely outdated and hence the corresponding short data type is also out data type.
int:
Size: 4 byteRange: -2147483678 to 2147483647
long:
Whenever int is not enough to hold big values than we should go for long data type.
Size: 8byteRange: -263 to 263-1
All the data types (byte, short, int, and long) can be used to represent whole numbers. If we want to represent real numbers then we should go for floating-point data type.
If we want to represent 5 to 6 decimal places of accuracy then we should go for float.
Size: 4 bytesRange: -3.4e38 to 3.4e38
double:
If we want to represent 14 to 15 decimal places of accuracy then we should go for double.
Size: 8 bytesRange: -1.7e308 to 1.7e308
boolean data type
Size: Not applicable (Virtual machine dependent)Range: Not applicable but allowed values are true and false.
char
size: 2 bytesRange: 0 to 65535
Comments
Post a Comment