Oop Finals
Oop Finals
● Encapsulation
Hides internal details of objects to protect data and simplify code changes. ● Common in caching, managing sessions, and dictionaries
● Polymorphism ● Sample 2
Allows the same method name to work differently depending on the object using it.
Data Structures ● Sample 3
● ArrayList
- A list that can grow or shrink as needed. Tips & Best Practices
- Can add items. ● Initial Capacity and Load Factor: Set these to avoid unnecessary resizing
- Can get items by position
- Can change items ● Avoid Frequent Resizing: Know the size in advance to avoid slowdowns
- Can remove items
- Can clear all items ● Thread Safety: Use thread-safe alternatives for shared use
- Can find out how many items are in it
- Can go through each item one by one ● Use Immutable Keys: Prevent issues by using keys that don’t change
● Allows Nulls: One null key, multiple null values allowed Use Case
● HashMap: When you need to connect a key to a value
● Not Thread-Safe: Use special versions for multi-threaded programs
● HashSet: When you just need a unique set of values
Usage