Chapter Two Review
Lesson:
Review:
- Unary Operators: ++, --, +, =, !, ~, and ().
- ! Operator: inverts the value of a boolean expression.
- ~ Operator: inverts the bit pattern of an integral expression.
- (type) Operator: Overrides the type of a variable to allow
assignments that the compiler would normally reject.
- Arithmetic Operators: *, /, %, +, and -.
- Integer Division: Integer division by zero will throw and exception.
- NaN: Not a Number.
- Shift Operators: The <<, >>, and >>>
operators perform bit shifts of the binary representation of the left
operand.
- Shift Operands: should be an integral type, either int or long.
- Bitwise Operators: &(AND), ^(XOR), | (OR).
- AND: a 1 bit results if the first operand bit and the second
operand bit are both 1.
- XOR: a 1 bit results only if exactly one operand bit is 1.
- OR: a 1 bit results if either the first operand bit or the second
operand bit is 1.
- Simple Assignment: The = assigns the value of the right-hand
operand to the left-hand operand.
- Compound Assignment Operators: The op = construct when applied to
an expression like "a op= b;" appear to behave like "a = a op b;"
- Compound Assignment Operators: exist for all binary non-boolean
operators: *=, /=, %=, -=, +=, <<=, >>=, >>>=, &=, ^=, and |=.
Assignment:
Consider the following sample applet:
-------------------
import java.awt.*;
import java.applet.*;
public class col extends Applet{
int c = 0x00ffff;
int y = 0xffff00;
public void init(){
setBackground(Color.black);
}
public void paint(Graphics g){
g.setColor(new Color(c));
g.fillRect(10,10,20,20);
g.setColor(new Color(y));
g.fillRect(40,10,20,20);
g.setColor(new Color(c|y));
g.fillRect(70,10,20,20);
g.setColor(new Color(c&y));
g.fillRect(100,10,20,20);
}
}
--------------------
ASSIGNMENT:
You will show the AND, XOR, and OR results for the following colors: MAGENTA
(ff00ff), RED, GREEN, BLUE, CYAN (00ffff), and yellow (ffff00). You will
make what likes three multiplication tables with the operation (XOR, OR, or
AND) in the upper, left corner of the table and the unmixed colors along the
top and left sides of the table.