Chapter Two Review


x

Lesson:
Review:
  1. Unary Operators: ++, --, +, =, !, ~, and ().
  2. ! Operator: inverts the value of a boolean expression.
  3. ~ Operator: inverts the bit pattern of an integral expression.
  4. (type) Operator: Overrides the type of a variable to allow assignments that the compiler would normally reject.
  5. Arithmetic Operators: *, /, %, +, and -.
  6. Integer Division: Integer division by zero will throw and exception.
  7. NaN: Not a Number.
  8. Shift Operators: The <<, >>, and >>> operators perform bit shifts of the binary representation of the left operand.
  9. Shift Operands: should be an integral type, either int or long.
  10. Bitwise Operators: &(AND), ^(XOR), | (OR).
  11. AND: a 1 bit results if the first operand bit and the second operand bit are both 1.
  12. XOR: a 1 bit results only if exactly one operand bit is 1.
  13. OR: a 1 bit results if either the first operand bit or the second operand bit is 1.
  14. Simple Assignment: The = assigns the value of the right-hand operand to the left-hand operand.
  15. Compound Assignment Operators: The op = construct when applied to an expression like "a op= b;" appear to behave like "a = a op b;"
  16. Compound Assignment Operators: exist for all binary non-boolean operators: *=, /=, %=, -=, +=, <<=, >>=, >>>=, &=, ^=, and |=.

x

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); } } --------------------


x

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.