Ok, this study guide is done changing! Note that the code for Asteroids is now on the snarf site -- “05_asteroids” under classwork.
-
• Debugging
-
❖ The difference between a runtime error (a “bug”) and a compile-time (or compilation) error
-
❖ A syntax error is a failure to use proper Java syntax (the failure to follow the rules of Java programming -- for example, forgetting a semicolon, or parentheses, or sending the wrong type of argument to a method). Syntax errors are compilation errors. These errors are usually signified by red squiggly underlines in Eclipse.
-
❖ A semantic error is when there is a difference between what your code means and what you think it means (in other words, a difference between what your code does and what you think it should do). For example, perhaps you wrote a “for” loop that stopped looping one iteration too soon. Semantic errors are runtime errors.
-
❖ Given some (fairly simple) code, be able to “hand-simulate” it and describe what it does. For example, pretend you put a breakpoint in a loop, and write what the values for certain variables would be at each loop step.
-
❖ Given code with a bug (a semantic error) and a description of what the faulty behavior of the program is, find the bug and explain how to fix it
-
• Collections
-
❖ Know the differences between the built-in Java array, and Java’s ArrayList class of objects
-
- The biggest difference is that you can add things and delete things from an ArrayList, changing its size dynamically. You have to re-create an entire array, on the other hand, if you want to change its size, since you can only set the size when you create it.
-
- You might use an ArrayList if you need more flexibility in how many things are in the list while the program is running -- for example, if you don’t know how many things will be in the list when you create it, and instead you just want to create them and add them as the program goes on
-
- Example of where an ArrayList makes sense: the FANG engine stores GameLevels in an ArrayList, and it stores the Sprites on the canvas in something similar, called a LinkedHashSet (like an ArrayList, this also grows and shrinks dynamically as you add and remove things) -- this is because the game engine has no idea how many sprites you are going to eventually want to add to the canvas; you just tell it each time you add one!
-
❖ Be able to write code to create a collection, add items to it, and access items in it (indexing)
-
❖ Know that you should normally use things like blocks.length, or blocks.size() instead of a number, and know why
-
• Loops
-
❖ Label the four parts of a loop: initialization, test (condition), update, and body
-
- Also, know what each part does
-
❖ Know that while and for loops are really equivalent in power; it’s up to the programmer to choose which one to use based on convenience
-
❖ Be able to write actual code for loops that...
-
- position a collection of Sprites in a simple pattern (like the grid in Breakout)
-
- determine an extreme value in a collection (for example, a min or max value)
-
- calculate a value (for example, sum the first twelve multiples of three)
-
• Colors
-
❖ Know that Colors in Java are made by combining the primary colors red, green, and blue
-
❖ How do you make white? or black? or grey? or purple?
-
❖ Know the range of values for each color
-
❖ How would you make a random color?
-
❖ How could you use a loop to create a range of colors and store them in a collection (a series of progressively lighter shades of red, for example)?
-
❖ Know how to use a color palette (a collection of colors) to assign different colors to each of a bunch of Sprites in a collection (where perhaps the collection of Sprites is larger than the collection of colors).
-
❖ You don’t have to memorize how to make a Sound, an ImageSprite, or a help file
-
• Searching and Sorting
-
❖ Hashing will not be on the test (except possibly as extra credit)
-
❖ If we doubled the size of a list you were searching for something in, how would that change the time it would take to find the thing using the linear search algorithm (in the worst case)? How about the binary search algorithm?
-
❖ If an algorithm takes 5 seconds to sort 10 things, and it takes 10 seconds to sort 20 things, what is its performance? -- O(N), or proportional to the number of things in the list -- because if we double the number of things, then the time it takes also doubles
-
- Similarly, O(N^2), or proportional to the square of the number of things in the list, means that if we double the number of things, then the time the algorithm takes quadruples (double squared = quadruple)
-
- O(log (N)), or proportional to the base-2 log of the number of things in the list, means that if we double the # of things, then the time the algorithm takes only increases by one (for example, log 8 = log 2^3 = 3, log 16 = 4, log 32 = 5, log 64 = 6, etc.).
-
- So, from fastest to slowest (O(log N) is the fastest): O(log (N)) < O(N) < O(N^2)
-
❖ Write out the binary search algorithm in English
-
❖ Be able to do a binary search on a short list of numbers
-
❖ Can you do binary search on unsorted lists? What kind(s) of search can you do on unsorted lists?
-
❖ Write out in English what “O(N^2),” or “O(N),” or “O(log(N))” means. For example, O(N^2) means “proportional to the square of the number of things in the list”
-
❖ Name one slow and one fast sorting algorithm
-
• Levels (we’ll discuss this stuff on Monday)
-
❖ Given a game’s code, what aspects of the game play change with each new level (ex., are there more asteroids? do they move faster? etc.)?
-
❖ Write a line of code to change an aspect of a game when the level changes.
-
❖ Why can’t we just use “startGame()” to re-initialize everything at the beginning of a level? (...perhaps because we don’t want everything to be reset at the start of a new level...)