01/28/09
03:52:43
1
04
CS 61B: Lecture 4
Wednesday, January 28, 2009
Today’s reading:
S&B pp. 1014, 4953, 75, 7879, 86, 117, 286287, 292, 660.
PRIMITIVE TYPES
===============
Not all variables are references to objects.
Some variables are primitive
types, which store values like "3", "7.2", "h", and "false".
They are:
byte:
A 8bit integer in the range 128...127.
(One bit is the sign.)
short:
A 16bit integer in the range 32768...32767.
int:
A 32bit integer in the range 2147483648...2147483647.
long:
A 64bit integer, range 9223372036854775808...9223372036854775807.
double:
A 64bit floatingpoint number like 18.355625430920409.
float:
A 32bit floatingpoint number; has fewer digits of precision.
boolean:
"true" or "false".
char:
A single character.
long values are written with an L on the end:
long x = 43L;
This tells the compiler to internally write out "43" in a 64bit format.
double and float values must have a decimal point:
double y = 18.0;
float values are written with an f at the end:
float f = 43.9f;
Object types
Primitive types

Variable contains a
reference
value
How defined?
class definition
built into Java
How created?
"new"
"6", "3.4", "true"
How initialized?
constructor
default (usually zero)
How used?
methods
operators ("+", "*", etc.)
Operations on int, long, short, and byte types.
x
x * y
x + y
x / y
< rounds toward zero (drops the remainder).
x  y
x % y
< calculates the remainder of x / y.
Except for "%", these operations are also available for doubles and floats.
Floatingpoint division ("/") doesn’t round to the nearest integer, but it does
round off after a certain number of digits determined by the storage space.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '01
 Canny
 Data Structures, Subroutine, boolean values, false , Integer class. int

Click to edit the document details