Data_Types_and_Ranges_in_Java
Data_Types_and_Ranges_in_Java
Java has two main types of data types: Primitive and Non-Primitive (Reference) data types.
**short**
- Size: 16 bits
- Range: -32,768 to 32,767
**int**
- Size: 32 bits
- Range: -2^31 to 2^31 - 1 (-2,147,483,648 to 2,147,483,647)
**long**
- Size: 64 bits
- Range: -2^63 to 2^63 - 1 (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
**float**
- Size: 32 bits
- Range: Approximately ±3.40282347E+38F (6-7 significant decimal digits)
**double**
- Size: 64 bits
- Range: Approximately ±1.79769313486231570E+308 (15 significant decimal digits)
**char**
- Size: 16 bits (1 character/2 bytes)
- Range: '\u0000' (or 0) to '\uffff' (or 65,535)
**boolean**
- Size: Depends on the JVM
- Range: true or false
Non-primitive types have all the same size (refer to their memory address) and do not store
the actual value directly, instead, they store references (pointers) to the memory location
where the actual data is stored.
Examples
public class DataTypesExample {
public static void main(String[] args) {
byte byteVar = 100;
short shortVar = 10000;
int intVar = 100000;
long longVar = 100000L;
float floatVar = 234.5f;
double doubleVar = 123.4;
char charVar = 'A';
boolean boolVar = true;
Understanding these data types and their ranges is fundamental to effective programming
in Java.