
Lecture Notes for Sept 9, 2004 (Wednesday).
Continue declarations and data types
Primitive types
int, long, short, byte โ integer space of different sizes โ when in doubt use int
1, 23, -459
float and double โ rational numbers โ float 7 positions, double 15 positions
3.1345, -55.000
char โ character representation โ See chart Appendix C
โ5โ, โxโ, โ โ
boolean โ values (and reserved words) of true and false
true, false
Reference type โ provides a user defined or java library means of adding abstract data types
String โ special built in class to represent character strings
โThis is a string of charactersโ, โ\nโ, โ\tโ, โ\โโ ๏ see escape character chart
All variables used, must be declared at the beginning of the method in which they are used. It is a
way of documenting the code.
An acceptable abbreviation for the declaration is:
int numberOne, numberTwo, numberThree; // note the space after each comma
OR
int numberOne,
numberTwo,
numberThree; // this format lets you describe each variable
Operations and Operators
Two meanings of +;
+ - addition of numbers
+ - concatenation of Strings
How does java decide? Think of the lab assignment
Context โ java is strongly typed.
Automatic conversion (widening not narrowing)
Order of evaluation - + is evaluated from left to right.
Ex: 75 + 89 + 62 Only one operation can be done at a time.
So when we mix the types (demo program):