-
Describe the differences between instance variables and class variables.
- Class (static) variables are shared by all members of the class. They cannot access instance members of the class.
- Instance variables are variables dependent on a specific instance of the class.
-
How do you declare an instance variable?
- variableType variableName;
- i.e., String firstName;
-
How do you declare a static variable?
- static variableType VARIABLE_NAME;
- i.e., static double PI_TO_TWO = 3.14;
-
What do the public and private modifiers do?
- The public visibility modifier (for classes, methods and data fields) denotes that they can be accessed from any other classes.
- The private visibility modifier makes methods and data fields accessible *only* from within its own class.
-
What is the purpose of constructor overloading?
To give a client more initializing options.
-
What is the difference between a convenience constructor and a designated constructor?
The designated constructor initializes the object most completely. The convenience constructors should call the designated constructor. A no-arg constructor is an example of a convenience constructor.
-
What are accessor methods?
Getters (to read state) and setters (to update state) are used to access instance variables (ivars) and class variables (cvars). You should use them whenever you need access to an ivar/cvar. Doing so reduces maintenance, avoids redundancy and offers flexibility.
-
What does UML stand for?
Unified Modeling Language
-
-
-
UML: underline
static (class)
-
-
-
UML: filled diamond
composition (object is fully owned)
-
UML: open diamond
aggregation (object is shared)
-
UML: open triangle
generalization (inheritance)
-
Know how to draw a UML class diagram.
Practice this!!!
-
What are two benefits of inheritance?
- Reusability - reuse code from parent class
- Extensibility - Use subclasses to extend the functionality superclasses (i.e., student -> graduate or undergraduate. Both share common traits, but have unique traits that student doesn't have and other subclasses don't require).
-
How do you declare a subclass?
- public class superClass {}
- public class subClass extends superClass{}
-
Know how to draw a UML class diagram showing class relationships (super, sub)
Practice this!!!
-
"Is a" applies to what type of class relationship?
inheritance
-
"Has a" applies to what type of class relationship?
composition
-
What is the benefit of polymorphism?
Polymorphism allows for the proper method (super- or sub-class) to be called at runtime (because of dynamic -runtime- binding).
-
How can you write a method so that it can be overridden?
- The method must exist in both the subclass and the superclass with the same name and the same argument lists (number and type).
- The return type of both methods must match.
- Don't declare the superclass private or final (or static if the classes are in the same file).
-
Discuss declared type and actual type and how they relate to polymorphism.
An object can be declared as the type of the superclass, but be of a subclass type. For example, if you create an array of Students, they can be Graduate or Undergraduate type objects. You can return the actual type of an object at runtime using instanceof. (if ( person1 instanceof undergraduate ))
-
What are declared type and actual type (with regard to polymorphism)?
- Declared type - determines if a method can be called
- Actual type - Provides actual implementation
-
What does polymorphism offer?
Polymorphism offers the desired flexibility that is needed in OO environments. It also allows code to be easily modified to allow for future needs.
-
What is the syntax for a subclass method to call a superclass method?
- Constructor: super() - for no-arg constructor
- super(args)
-
Method: super.method(args if needed)
-
Describe the try-catch method of exception handling.
When you are handling a checked exception, you must declare a checked exception if the method might throw it (e.g., throws FileNotFoundException). Then, you enclose the code that could throw the exception in a try block and handle the exception in the catch block.
-
Errors should be caught _____________.
locally
-
Errors should be handled in the ________________.
caller
-
Why benefit comes from detecting errors locally but handling them in the caller?
The error is caught to prevent errors in execution, but the exception is re-thrown to the caller to allow any clean-up that needs to take place as a result of the error. Otherwise the called method would terminate the program.
-
What happens when an exception is caught?
If one of the statements inside a try statement is caught, Java skips the remaining statements in the try block and trys to handle the exception. Each catch statement (on the stack of calling methods) is examined in turn to see if the caught exception is handled in that catch block. If so, it is executed. If nhot, it proceeds up the stack.
-
Name one advantage that storing data in binary form has over storing the same data in ASCII form.
ASCII requires 1 byte for each character, while binary can store data using fewer bits.
-
Binary is/is not readable.
is not
-
Text is/is not readable.
is
-
Storing data in binary form is more ________________ because it does not require encoding/decoding.
efficient
-
Name the 4 stream classes and what they are used for.
- FileXXXStream - bytes
- DataXXXStream - primitive/String
- BufferedXXXStream - buffered bytes
- ObjectXXXStream - objects, primitives
-
Declaring a stream for specified IO will likely require _______________.
nesting of streams
-
Why is the Serializable interface used?
It allows class hierarchies to be read to/written from disk.
-
What is the syntax for declaring a generic class?
public class Stack {}
-
What is the syntax for declaring a generic method?
public void display(T[] list)
-
What are the advantages of generics?
- *compile time error checking
- *flexibility
-
Are generics available at runtime?
No. They are replaced by Java at runtime with concrete classes.
-
When you use generics, can you use any data type at runtime?
No. Primitive types must be wrapped (or boxed). For example, int becomes Integer.
-
What does boxing do?
Converts a primitive type to an object (e.g., int to Integer).
-
What does unboxing do?
Converts an object to a primitive type (e.g., Integer to int).
-
What does erasure do?
- *provides backward compatibility
- *Raw syntax is rewritten to use generics
- *generic bounding wildcards (?, ? extends)
-
Name the two types of containers.
Collections and maps
-
Name and describe the three types of collections.
- Set: unordered no duplicates
- List ordered dups allowed
- Queue ordered (FIFO) dups allowed
-
Describe the characteristics of a map.
A map is composed of key/value pairs. There can be no duplicates (due to the hashing algorithm) and search is very fast.
-
-
What are some important characteristics of the ArrayList data construct?
- *array implementation
- *dynamically increases
- *maintains order of insertion
- *requires shifting during insertions/deletions
-
What are some important characteristics of the LinkedList data construct?
- *linked implementation
- *dynamically increases/decreases
- *maintains order of insertion
- *does not require shifting durint insertions/deletions
-
When should you use the Comparator interface?
When classes don't impelement the Comparable interface, and when the classes are not the same but share common characteristics.
-
What does the Comparator interface offer?
- *can compare in a non-natural order
- *can compare dissimilar objects
- *offers compare method
-
What are some important characteristics of the Stack data construct?
- *LIFO
- *reverses order of insertion (when popped)
- *push and pop ONLY at the TOP of the stack
-
What are some important characteristics of the Queue data construct?
- *FIFO
- *maintains order of insertion
- *insert at the end of the queue (push)
- *remove at the front of the queue (pop)
-
What are some important characteristics of the Priority Queue data construct?
- *insert at the end of the queue
- *remove at the front of the queue
- *order of insertion not maintained (due to prioritization)
- *value with highest priority moves to the front of the queue
-
What are some important characteristics of the Linked List data construct?
- *each node is linked to the next one
- *order of insertion is maintained
- *uni-directional traversal (head to tail)
-
What are some important characteristics of the Deque data construct?
- *queue, but with
- *bi-directional traversal (head to tail and tail to head)
-
Name 3 characteristics of Sets:
- *no duplicates
- *insertion order not maintaines
- *can be searched fast
-
Give a distinguishing characteristic of a HashSet.
It uses a hashcode for fast searching.
-
Give a distinguishing characteristic of a LinkedSet.
It maintains order of insertion.
-
Give a distinguishing characteristic of a TreeSet.
It provides sorting order (increasing or decreasing)
-
Name 5 characteristics of Maps:
- *key-value pairs
- *key is usually a string
- *value can be any object
- *no duplicates
- *fast searches
-
Give a distinguishing characteristic of a HashMap.
It uses a hash code for fast searching
-
Give a distinguishing characteristic of a LinkedMap.
It maintains insertion order.
-
Give a distinguishing characteristic of a TreeMap.
It provides sorting order (increasing or decreasing).
-
Bubble Sort, Insertion Sort and Selection Sort are good only for ______________ data sets.
small
-
Bubble Sort, Insertion Sort and Selection Sort require ______________ passes.
n - 1, where n is the number of items in the set to be sorted
-
Bubble Sort is different from Insertion Sort and Selection Sort in that it offers _________________.
quick exit. It knows when it is finished; the others have to sort to the end of the set to ensure completion.
-
Mergesort and Quicksort use ____________________ implementations.
recursive
-
Mergesort and Quicksort can be used for _______________ data sets.
large
-
Mergesort can be used with ___________________ as well.
external data
-
The Heapsort method is based on a _______________________ (also known as a heap).
binary tree
-
Describe the Heapsort algorithm.
- *Build heap, remove root successively
- *add to the bottom, rebuild heap
- *remove root, rebuild heap
-
Describe the Radix Sort.
- *sorts n values, each m digits in length
- *starts with least significant digit (lsd) and progresses to most significant digit (msd)
- *uses value-based bins to distribute digits
|
|