Chapter 2
Chapter 2
PROGRAMMING 1
COS 011
More Printing
2
$$1_1
numberOfBeans
public (reserved word)
1day
peanutbutter&jelly
aZ_b
INT
Good variable names
14
Do not use $
Avoid names that are identical other than
differences in case
Use meaningful names
Avoid excessive length
Using +
15
Available at:
http://download.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html.
18
Composition
19
Example:
FirstName=“Abdullah”;
Age=30;
To sum up, the concept beyond this process is:
When you declare a variable, you create a named storage location.
When you make an assignment to a variable, you give it a value.
22
int n = 5/2;
int k = 9/10;
Differences between int and double
35
5 is an int.
5.1 is a double.
5.0 is a double.
5.7f is a float
Range of values:
int -2 billion to+2 billion
double 4.9x10-324 to1.8x10308
float 1.4x10-45 to3.4x1038
Float vs. double
36
int i;
double d = 12.9;
i = (int) d; //What do you think is in i now?
1. variable
2. value
3. type
4. keyword
5. declaration
6. assignment
7. expression
8. operator
9. composition
Exercise
47
Questions ?!