What happensinside
the computer
when you define
a variable int a:
The computer
will find
some used memory cells
and mark them as
used
(a.k.a.:allocate memory)
Then the computerequates (= "records") the
name a to the
memory location of the
reserved cells
Schematically:
Data type of a
variable
Eachvariable has a
data type
The data type specifies
the kind of
information
Each kind of
information has its
ownway of
representation
The way of
representation is
called a
code
Encoding method of
a data type
Information of
a data type are
represented by
binary numbers
The encoding methoddefines the
way to
interpret
a binary number
My way to
explain"data type":
Data type provide the
context to
interpret
a number
and obtain the
meaning of the
number
Example that context in
necessary to
interpret
a number value
The data typedetermineshow the
Java program
will
interpret the
value 65:
public class datatype
{
public static void main(String[] args)
{
int x = 65;
System.out.println(x); // Print 65 as an integer
char y = 65;
System.out.println(y); // Print 65 as Unicode
}
}
Conclusion:
The date type provides
the context
on how to
interpret
a number inside the computer
DEMO:
demo/02-review/datatype.java
The reason why
65 is the
letter A is the
Unicode used to
representsymbols:
Example of the
effect of
the context
in the English language
Make a
correctEnglish sentence that
begins with:
You is ....
Answer:
You is ....
Example of the
effect of
the context
in the English language
Make a
correctEnglish sentence that
begins with:
You is ....
Answer:
You is a word in the English language
Explanation:
"You" is
usuallyused as
a personal pronounce
(= context)
You must not use
the word "you"
in this context to
solve this puzzle
Java's primitive data types
Data type
Encoding method
byte
2's complement encoding using
8 bits
short
2's complement encoding using
16 bits
int
2's complement encoding using
32 bits
long
2's complement encoding using
64 bits
float
IEEE 754 encoding using
32 bits
double
IEEE 754 encoding using
64 bits
char
Unicode encoding using
16 bits
boolean
Enumeration encoding using
0 = false and
1 = true
You will learn about these
encoding methods in
CS 255