What does UML stand for?
Unified Modeling Language
What does the final keyword mean?
It makes an attribute or method non-changeable.
How are interface implementation represented in a UML diagram? How are class implementation represented in a UML diagram?
Interfaces - dotted line with open arrowhead
Classes - solid line with open arrowhead
It defaults to Object's toString() unless overridden and is used to print attributes of of the object
What is the time complexity for
1. appending elements to the end of an ArrayList
2. checking if an ArrayList contains a certain element (worst case)
3. appending element to the front of an ArrayList
O(1)
O(n)
O(n)
What are the 3 parts of a UML class box?
1) Class name
2) attributes and their types
3) method names with return types and parameters
What does the keyword static mean?
The same variable or method can be accessed without creating an object of the class (i.e. variables exist at the class level, not object level)
What is the keyword to implement an interface? What is the keyword to implement a parent class?
implements and extends
What does equals() do and write out an equals() on the board :)
1. Check if the Object parameter is an instance of your object
2. Typecast the Object parameter into your object type
3. Return a boolean expression (using == for primitive and .equals() for objects )
What is the time complexity of
1. inserting element into a HashSet
2. seeing if an element is contained in a HashSet
O(1)
O(1)
What does the word public mean?
Can be accessed and modified by the same class, subclasses, and other classes
What does Polymorphism mean?
The condition of occurring in several different forms
How do subclasses access private attributes from a superclass?
- use getter methods, such as super.getName();
- when you override a method from a super class make sure to use the EXACT same method header
What is the purpose of a hashCode() and write one out on the board :)
- to return a unique hashcode value for the object
- if you consider two objects to be equal they must have the same hashcode
public int hashCode(){
return this.name.hashCode() + this.id
What is the time complexity for
1. adding an element to a TreeSet
2. removing an element from a TreeSet
3. accessing an element in a TreeSet
All have O(logn)
What does the word private mean?
Can be accessed and modified by the same class only
What does the word Overloading mean?
Two method have the same name but different parameters
Overriding is different than overloading. Overriding is when a subclass has the same method as the parent class, but you want the subclass' version to be implemented
What can/cannot an interface do?
- Cannot be instantiated
- Can only contain method signatures and static fields
- Everything must be public
- is-a relationship
What is the purpose of compareTo() and come up and write the the method on the board :)
-takes in 1 argument
-from the Comparable interface
-returns an int: <0 if this is lesser / =0 if this and o are equal / >0 this is greater
-located in the class
-uses natural ordering
What is the time complexity for
1. accessing the value in a HashMap
2. adding a value to a HashMap
All O(1)
What does the word protected mean?
Can be accessed and modified by the same class and its subclasses
What does Encapsulation mean?
The bundling of data with the methods that operate on the data into a class. It reduces program complexity
What is the difference between an interface and an abstract class?
-Interfaces do NOT have any implementation, while abstract classes do. Abstract class only need to have one method abstract which must be implemented by the subclass using the @Override
What is the purpose of compare() and come up and write it on the board :)
-takes in 2 arguments
-from the Comparator interface
-returns custom ordering
-located in a separate class
What are the differences between TreeMap, TreeSet, HashMap, and HashSet?
HashMap - unordered, key-value pair
HashSet - unordered, value
TreeMap - ordered, key-value pair
TreeSet - ordered, value