Data Types
Byte Data Type
syntax: byte variable;
Values that can be stored in a byte variable are as follows:
Inital Value
|
Storage in Memory
|
Value range
|
0 |
8 bits |
-128 -- 127 |
Used in a line of code:
byte number;
Short Data Type
syntax: short variable;
Values that can be stored in a short variable are as follows:
Inital Value |
Storage in Memory |
Value range |
0 |
16 bits |
-32768 -- 32767 |
Used in a line of code:
short number;
Integer Data Type
syntax: int variable;
Vaules that can be stored in a int variable are as follows:
Inital Value |
Storage in Memory |
Value range |
0 |
32 bits |
-2147483648 -- 2147483647 |
Used in a line of code:
int number;
Long Integer Data Type
syntax: long variable;
Vaules that can be stored in a long variable are as follows:
Inital Value |
Storage in Memory |
Value range |
0 |
64 bits |
-1018 -- 1018 |
Used in a line of code:
long number;
Floating point decimal Data Types
syntax: float variable;
Values that can be stored in a float variable are as follows:
Inital Value |
Storage in Memory |
Values range |
0.0 |
32 bits |
-1038 -- 1038 |
Used in a line of code:
float number;
Double Floating point decimal Data
Types
syntax: double variable;
Values that can be stored in a double variable are as follows:
Inital Value |
Storage in Memory |
Values range |
0.0 |
64 bits |
-10308 -- 10308 |
Used in a line of code:
double number;
Boolean Data Type
syntax: boolean variable;
Values that can be stored in a boolean variable are true & false.
Used in a line of code;
boolean isSmart = true;
Type Casting
int num1; short num2; byte num3; float num4; double
num5;
num5 = (double)( num1 + (int) num2) - (double)((float)
num3 - num4);
The last line changes variable types so that numbers can be added together.
|