JMU
Data Types and Variables
An Introduction with Examples in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Data and Values
Variables and Constants
A Little Background on Digital Computers
Data Representation - The Counting Numbers
images/counting-numbers.gif
Data Representation - Negative Integers
Going Further: Negative Numbers
Going Further: Negative Numbers (cont.)
images/twos_complement.gif
Going Further: Negative Numbers (cont.)
http://imgs.xkcd.com/comics/cant_sleep.png
(Courtesy of xkcd)
Data Representation - Real Numbers
Going Further: Real Numbers (cont.)
Going Further: Real Numbers (cont.)
Data Representation - Characters
Data Representation - Characters (cont.)
Some Atomic/Primitive/Fundamental Types in Java

Type Memory Range
byte 1 byte -128 to 127
short 2 bytes -32,768 to 32,767
int 4 bytes -2,147,483,648 to 2,147,483,647
long 8 bytes \(-2^{63}\) to \(2^{63}-1\)
float 4 bytes
double 8 bytes
char 2-4 bytes Unicode
boolean true or false

Data Representation - Some Non-Atomic Types
Non-Atomic Types in Java
Some Non-Atomic Types in Java
Variables in Java
Variables in Java (cont.)
Nerd Humor
http://imgs.xkcd.com/comics/x.png
(Courtesy of xkcd)
Variable Declarations
Declaration Statements in Java
Declaration Statements in Java (cont.)
Expressions Revisited