Java Reference
In-Depth Information
Why Eight Bits?
A byte is a memory location that can hold 8 bits. What is so special about 8? Why not
10 bits? There are two reasons why 8 is special. First, 8 is a power of 2 (8 is 2 3 ). Since
computers use bits, which have only two possible values, powers of 2 are more convenient
than powers of 10. Second, it turns out that 7 bits are required to code a single character of
the ASCII character set. So 8 bits (1 byte) is the smallest power of 2 that will hold a single
ASCII character.
Display 5.10
Variables in Memory
Main Memory
byte 0
byte 1
byte 2
byte 3
byte 4
byte 5
byte 6
byte 7
byte 8
variable1 (3-byte location with address 0)
variable2 (2-byte location with address 3)
variable3 (1-byte location with address 5)
variable4 ( 3-byte location with address 6 )
References
In order to have a simple example to help explain references , we will use the class
ToyClass defined in Display 5.11 .
Variables of a class type name objects of their class differently than how variables
of primitive types, such as int or char , store their values. Every variable, whether of a
primitive type or a class type, is implemented as a location in the computer memory.
For a variable of a primitive type, the value of the variable is stored in the memory
location assigned to the variable. However, a variable of a class type stores only the
memory address of where an object is located. The object named by the variable is
stored in some other location in memory, and the variable contains only the memory
 
 
Search WWH ::




Custom Search