You are on page 1of 1

Variables and Data Type

 Primitive Data Types – has guaranteed specified range of bits or values on the data types
in order to achieve portability without porting any machine architecture.
o Integers – whole-valued signed values (+-), does not support unsigned
 Byte – Width (8 bits), Range (-128 to 127)
 Short – Width (16 bits), Range (-32,768 to 32,767)
 Int – Width (32 bits), Range (-2,147,483,648 to 2,147,483,647)
 Usually used in control loops as a counter, you may think using
byte and short would be better but they will be type promoted to
integer so it is better to use int.
 Long – Width (64 bits), Range (-9,223,372,036,854,775,808 to
9,223,372,036,854,775,807)
 Usually used when numbers become arbitrarily big like the speed
of light for example.
 Note: Width should be look as a behavior not as a storage– defining for
variables and expressions of that type.
o Floating-point numbers – decimal/fractional precision (another term real
numbers)
 Float – Width (32 bits)
 Imprecise when value becomes too small or too big
 Double – Width (64 bits)
 Better to just use double better performance overall in modern
computers
o Characters
 Char – symbols in a character set – letters and numbers
 Width (16 bits), Range (0 to 65,536)
 Uses Unicode for global portability
 Char can be used similar to integer by adding its value resulting in
another character inside the Unicode or ASCII
o Boolean
 Boolean – true/false
 Use in conditional statements
 Paired with relational operators
 Sufficient by itself even without conditional statements

You might also like