Explaination :
- Data types in any of the language means that what are the various type of data the variables can have in that particular language.
- Information is stored in a computer memory with different data types.
- Whenever a variable is declared it becomes necessary to define data type that what will be the type of data that variable can hold.
- The term data type refers to the type of data that can be stored in a variable.
- Sometimes, Java is called a “strongly typed language” because when you declare a variable, you must specify the variable’s type.
- Then the compiler ensures that you don’t try to assign data of the wrong type to the variable.
Data Types available in java are:
Integer Types
Type | Contains | Default | Size | Range |
---|---|---|---|---|
byte | Signed integer | 0 | 8 bit or 1 byte | -27 to 27-1 or -128 to 127 |
short | Signed integer | 0 | 16 bit or 2 bytes | -215 to 215-1 or -32768 to 32767 |
int | Signed integer | 0 | 32 bit or 4 bytes | -231 to 231-1 or -2147483648 to 2147483647 |
long | Signed integer | 0 | 64 bit or 8 bytes | -263 to 263-1 or -9223372036854775808 to 9223372036854775807 |
Rational Numbers
Type | Contains | Default | Size | Range |
---|---|---|---|---|
float | IEEE 754 floating point single-precision | 0.0f | 32 bit or 4 bytes | ±1.4E-45 to ±3.40282347E+38F |
double | IEEE 754 floating point double-precision | 0.0 | 64 bit or 8 bytes | ±439E-324 to ±1.7976931348623157E+308 |
Characters
Type | Contains | Default | Size | Range |
---|---|---|---|---|
char | Unicode character unsigned | \u0000 | 16 bits or 2 bytes | 0 to 216-1 or \u0000 to \uFFFF |
Conditional
Type | Contains | Default | Size | Range |
---|---|---|---|---|
boolean | true or false | false | 1 bit | true or false |