- Uses an array of linked lists (buckets). - Uses hashCode() to find the bucket. - Uses equals() to check key equality.
9. What is a constructor in Java?
- A block of code invoked when an object is created. - Types: Default, Parameterized.
10. What is the difference between ArrayList and LinkedList?
- ArrayList: dynamic array, faster for accessing elements. - LinkedList: doubly linked list, faster for insertion/deletion.
11. What is the purpose of the 'transient' keyword?
- Prevents serialization of variables.
12. What is the use of the 'volatile' keyword?
- Ensures visibility and ordering of variables in multithreading.
13. What is method overloading and method overriding?
- Overloading: Same method name, different parameters (compile-time). - Overriding: Same method name and parameters, different class (runtime).
14. What is a Singleton class?
- A class with a single instance using private constructor and static method.
15. What is the 'super' keyword used for?
- Access parent class members and constructors. 16. What is the difference between abstract class and interface? - Abstract class: partial abstraction, can have concrete methods. - Interface: full abstraction, no concrete methods (before Java 8).
17. What is a marker interface?
- An interface with no methods (e.g., Serializable).
18. What is garbage collection in Java?
- Automatic memory management by JVM to deallocate unused objects.
19. How to create a thread in Java?
- Implement Runnable interface or extend Thread class.
20. What are functional interfaces in Java?
- An interface with a single abstract method (e.g., Runnable, Callable).