Judy Sheard’s third week lecture continued on the introduction to Java and programming as a whole. Although all of the concepts covered were very basic some of the terminology needs to be learned, particularly for when in the work place and the need to communicate arises. So, a summary of the terms covered and their contextual definitions:

- Selection – if construct, 3 components: condition,consequent, alternative. if(keyword) (condition){consequent}else{alt}
- relational operator – ==, !=, <, >, <=, => result of these operators is a boolean TRUE/FALSE
- boolean expression – using one of the above operators.
- compound statement – multiple lines in consequent block.
- nested if – if within and if construct.
- logical operators – !, && , || NOT, AND, OR can be used in conjunction with boolean expressions.
- switch statement – can be used to neaten cascading if statements (compiles as cascading ifs however) ideal for day of the week statements etc. Can only be used with int and char expression evaluations.
- shorthand arithmetic operators – a += 1; a -=1; a *=2; a /=3; a %=5; //reassign a with the result of the operators. a++; ++a; b–; –b; // if ++, — is after the variable then the arithmetic will be applied after the entire statement.
- local variables – variables within methods which exist only as long as the method is being executed.
- base input – using scanner method to read from keyboard

Precedence rule for evaluating expressions (JAVA):

- Parenthesis
- Unary Operators (++, –, !)
- Binary Arithmetic Operators (*, /, %, +, -)
- Relational Operators (<, >, <=, =>, ==, !=)
- Logical Operators ( &&, ||)
- Shorthand arithmetic ( =, +=, -=, *=, /=, %=) // these ones are evaluated right to left.

When in doubt of any of the above its much easier just to use parenthesis…

**Pearl of the week: **(I was always under the impression that a leap year is simple every 4th year, this is not the case however)

Algorithm for leap years:

1 2 3 4 |
<strong>if</strong> (year modulo 4 is 0) <strong>and</strong> (year modulo 100 is not 0) <strong>or</strong> (year modulo 400 is 0) <strong>then</strong> is_leap_year <strong>else</strong> not_leap_year |

Hope all banking systems have this correctly coded otherwise the 2100 bug might turn out to be more exciting than y2k.

The tut again was simply a revision of the lecture with the chance to ask question and get explanations. We are getting the assignment outline this week, Judy has said it is not really challenging…

1 2 3 4 |
<strong>if</strong> (year modulo 4 is 0) <strong>and</strong> (year modulo 100 is not 0) <strong>or</strong> (year modulo 400 is 0) <strong>then</strong> is_leap_year <strong>else</strong> not_leap_year |