ulrail.gif

Exam 2 Review

  ur-2c.gif urrail.gif
blrail-nonavbar.gif

Home | Resources | Homeworks | Exams
Lectures | Labs | Contacts | Submit | TAs

br-2a.gif   br-2c.gif brrail.gif
spacer.gif spacer.gif

Exam 2 Review

These are the review points from the Jeopardy game played in class during the lecture before the second exam.

While Loops: A while loop executes while the condition is true, and stops executing once the condition becomes false
While Loops: With DeMorgan's law, you negate each of the operands (here, p and q) and you switch the sign
While Loops: At the start of each loop iteration, including the first
While Loops: This loop will repeat forever
While Loops: A while loop never executes the body if the boolean condition is initially false

For Loops: The ForInit is executed once only, and right before the first iteration of the for loop.
For Loops: The ForUpdate is executed once for every iteration of the for loop, and done at the end of the loop body (or action).
For Loops: At the start of each loop iteration, including the first
For Loops: The variable is not visible once the for loop finishes.
For Loops: Given for (int i; ...; ... ) { ... }, the variable i is local to the for loop body.

Misc: ++i will first increment the value, then use it; i++ first uses the value, the increments it
Misc: Recall that Java will initialize fields of a class to default values, but not variables in a method
Misc: Java will not assign values to variables declared within methods (or within blocks within methods). Also, variables can be declared within a block.
Misc: ?: can be used if both parts will return a value. For example: int x = (y<1)?5:6;.
Misc: The only difference with a System.in Scanner is the parameter passed to the constructor; all the other methods work the exact same.

Loop controls: That's what a break statement does
Loop controls: It's on the resources page
Loop controls: Although a continue starts a new iteration of the loop, Java will execute the ForUpdate part of a for loop.
Loop controls: A break immediately stops execution of the loop, and does not evaluate any parts (the boolean expression, ForUpdate, etc

Nested loops: The number of times the inner-most loop body executes is the product of the number of times each of the loops iterates.
Nested loops: The number of times the inner-most loop body executes is the product of the number of times each of the loops iterates.
Nested loops: I ran out of nested loop questions to ask
Nested loops: Java applies the loop controls (break and continue to the most recently entered loop.
Nested loops: If you got this one wrong....

Constructors: Remember these four parts!
Constructors: The 'default' constructor always has no parameters
Constructors: A specific constructor always has one or more parameters
Constructors: A constructor is used to construct (create) and initialize a new object
Constructors: This isn't necessary for this exam

Constructors again: There can be only one (technically, there can be zero as well)
Constructors again: You can put in as many specific constructors as you want
Constructors again: This is how Java tells a constructor from the other methods
Constructors again: You do not specify a return type for a constructor - this is different than specifying 'void'
Constructors again: All constructors (that we've seen so far) must be public

Creating classes: This is how behaviors are implemented in Java
Creating classes: This is how attributes (or properties) are implemented in Java
Creating classes: The name 'accessor' is just a fancy name for a method that does this
Creating classes: The name 'mutator' is just a fancy name for a method that does this
Creating classes: The name 'facilitator' is just a fancy name for a method that is not one of the other three types

Methods: The keyword void means that no value is returned from the method
Methods: The value returned by the foo() method gets copied into the variable x
Methods: System.out.println does not return a value, thus is has a void return type
Methods: Not always, but for this course, they pretty much always will
Methods: Not always, but for this course, they pretty much always will


spacer.gif
spacer.gif footer-middle.gif spacer.gif