Algorithms: ----------- 1. What are the three parts of an algorithm? With this in mind, give an algorithm that describes how to read a book aloud. 2. Aside from the three parts of an algorithm, what are other considerations you must take into account when writing one? With this in mind, give an algorithm that describes how to read a book aloud. Variables: ---------- 1. What are the four base types we used? What does "type casting" mean? Show how to cast an integer to a double. Explain why you can't cast a boolean to an integer. 2. What does the program "state" refer to? How can you examine the program state? How can you modify it? Operators: ---------- 1. Why can't you do if (3 < x < 5) ? Give a valid Java expression that accomplishes the same thing. 2. Precedence: What is the order of evaluation for this expression? 2 * ++b - (10 + 2) * 7 Precedence: What is the order of evaluation for this expression? b < 3 || !c && !(a == 3) 3. In Java, the ^ operator doesn't do exponentiation. What DOES it do? Conditional statements: ----------------------- 1. What is the syntax for an "if" statement? What is the syntax for a "switch" statement? 2. Do you have to have an "else" clause attached to every "if" statement? What is the "dangling else" problem? 3. When is a "switch" statement more appropriate than a series of "if" statements? Give an example of a switch statement, and an equivalent version that uses "if-else" statements instead. Loops: ------ 1. What is the syntax for a "do" loop? What is the syntax for a "for" loop? 2. How might you decide whether to use a "do" loop or a "for" loop, in a given situation? Give an example of an appropriate use of each one. Style: ------ 1. Give some good rules to follow when naming variables. 2. Give some good rules to follow for using whitespace. 3. What does "self-documenting code" mean? What facilities does Java provide to help you write such code? 4. Describe good indenting style, and how curly braces should be used. 5. Where should you have comments in your code? Methods: -------- 1. How do you know when it would be a good idea to create a new method? 2. What does a method declaration look like? What information is contained in the declaration? 3. How do you indicate that a method doesn't return a value? For methods that return a value, you must return a value at some point. Does Java also require an explicit "return" in a method that doesn't return a value? 4. What is the difference between formal and actual parameters? Give an example that illustrates the difference. 5. What is Java's passing convention? How come sometimes methods get a "copy" of a variable (so the original is unchanged) and sometimes they get a "reference" to the variable (so the original can be changed)? Give an example of each kind of method. Scope: ------ 1. What does "scope" mean? What dictates the extent of a variable's scope? 2. If I have a for loop such as: for (int i=0; i<10; i++) { ... } why can't I access variable i after the loop terminates? What should I do to make it possible to access variable i? 3. What does "variable shadowing" mean? If a global static variable is being shadowed, how can you get access to it anyway? What if it's a global nonstatic variable? OOP: ---- 1. What is the difference between the keywords static and final, for variables? What is the difference between the keywords static and final, for methods? 2. Why are object variables declared to be private? 3. What does a constructor do? What is special about a "default" constructor? If you don't provide one, what happens if you do Classtype var = new Classtype(); ? 4. Use of "this" is often optional. When are times that you MUST use "this"? 5. Why do classes need update and accessor methods? What is the difference between the two? 6. What is the difference between a reference and an object? What does "aliasing" mean? 7. I can create new objects with "new". How do I get rid of objects I'm no longer using, so that memory doesn't fill up? 8. Encapsulation and abstraction are closely related terms. How can we distinguish between them? Why do we bother designing classes that are "properly encapsulated"? 9. How is a static method different from a non-static method? How do you call each kind? Give an example of calling a static method, and another example of calling a non-static method. Graphics: --------- 1. How is the screen coordinate system set up? What is the word for a specific (x,y) coordinate on the screen? Why must the input parameters to drawing methods always be integers (instead of, for example, doubles)? Arrays: ------- 1. Give the syntax for a general (could be more than one dimension) array declaration. 2. After declaring an array variable, when do you have to loop through the array and create a new object for each entry? Why do you have to do this? 3. How do you access an element in an array? How do you update it? 4. What is an initializer list? Give an example of initializing an integer array of size 3. Give an example of initializing a Spaceship array of size 3. (Loops are not allowed!) 5. Why did we require that you make a copy of the input Card array in the BridgeHand constructor? Sorting: -------- 1. Apples and Bananas are not directly comparable. If I want to be able to compare the two, what should I do? 2. Bubble Sort is an expensive algorithm in that each time through the loop, it compares all theneighboring array values. Name two ways to improve the efficiency of Bubble Sort and explain why they help. Inheritance: ------------ 1. What is the difference between method overloading and method overriding? Give an example of each, from any class discussed in lecture or on an assignment. 2. If a method has been overridden in a child class, how can you call the parent's corresponding method from inside the child class? Why might you want to do this? 3. What are some Object methods that are commonly overridden by classes we create? Give their declarations. 4. How can you prevent a method from ever being overridden? How can you prevent a class from being inherited? What can you do if you want an instance variable to be directly accessible from a child class, but not from any other class? 5. If B inherits from A, you can store a B object in an A reference: A a = new B(); Is this the same as when we do: double d = 10; // 10 is an integer ? If so, explain. If not, what is different? Interfaces: ----------- 1. What is an interface? Name at least one interface you've heard of. 2. Why do we use them? Name at least one interface you've heard of. 3. How are interfaces different from using inheritance? How are they similar? Encryption: ----------- 1. Why is general substitution more secure than Caesar shift encryption? Use numbers to support your answer.