0% found this document useful (0 votes)
29 views

Variables and Data Types

Primitive data types in Java include integers, floating-point numbers, characters, and booleans. Integers come in byte, short, int, and long varieties with different bit widths and value ranges. Floating-point numbers are used for decimal values and come as float or double. Characters represent symbols and have a width of 16 bits. Booleans represent true/false values and are used in conditional statements.

Uploaded by

Richmond Chua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Variables and Data Types

Primitive data types in Java include integers, floating-point numbers, characters, and booleans. Integers come in byte, short, int, and long varieties with different bit widths and value ranges. Floating-point numbers are used for decimal values and come as float or double. Characters represent symbols and have a width of 16 bits. Booleans represent true/false values and are used in conditional statements.

Uploaded by

Richmond Chua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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