- Access Modifiers
- Comparable v/s Comparator
- Abstract class v/s Interface
- final, finally, finalize
- Threads
Encapsulation | Encapsulation is a technique used for hiding the properties and behaviors of an object and allowing outside access only as appropriate. It prevents other objects from directly altering or accessing the properties or methods of the encapsulated object. |
Abstraction | Abstraction refers to the act of representing essential features without including the background details or explanations. Showing the functionality but hiding the implementation. |
Polymorphism | "one interface, many implementations." |
Inheritance | extending the properties of a parent class. |
HashMap | There can only be one null key in HashMap. Buckets stored as linked list. What if when two different keys have the same hashcode ? If there are more than one object mapped to the same hash value, we traverse through linked list, comparing keys in each entries using keys.equals() until it return true. Then the corresponding entry object Value is returned. In case we have to do a deep comparison of the fields, we override equals method. |
HashSet | Uses hashmap internally to maintain the uniqueness. Override equals method to do a deep comparison of each of the attributes. |
Vector | Used when you don’t know what type of objects will be inserted. Initial capacity and increment factor when resized upward. |
String/StringBuffer/StringBuilder | |
ArrayList v/s LinkedList | |
Stack | Heap |
stores temporary variables by each function. On function exit, values are popped out and memory is freed | stores objects created during runtime. When the function exits, reference is lost but the memory is not freed yet. Garbage collector does the work |
Fast access as stored sequentially. | Slow access because have to follow links. |
Has size limits. Might cause stackoverflow error when the function goes into infinite recursion. | No size limits, but sometimes might run out of Heapspace if no memory is free to be allocated. |
Memory automatically managed | Not managed automatically. |
Hashset | Treeset |
Not ordered | Ordered |
Null value allowed | Null value not allowed |
Performance - O(1) | Performance- log(n) |
Implements Hashmap | Implements Treemap |
final - to make an object immutable, to prevent a method from being overridden, to prevent a class from being inherited.
finally - always called after try catch
finalize - called before freeing the object by garbage collector.
References:
- http://javahungry.blogspot.com/2013/08/hashing-how-hash-map-works-in-java-or.html
- http://stackoverflow.com/questions/215497/difference-among-public-default-protected-and-private
- http://www.java2blog.com/2013/02/difference-between-comparator-and.html
Useful links: