[go: up one dir, main page]

0% found this document useful (0 votes)
3 views1 page

Oop Finals

The document outlines key concepts of Object-Oriented Programming, including encapsulation, inheritance, and polymorphism, which enhance code efficiency and reusability. It also discusses data structures like ArrayList, LinkedList, HashMap, and HashSet, highlighting their functionalities and best practices for usage. Additionally, it compares HashMaps and HashSets, detailing their purposes, structures, operations, performance, and appropriate use cases.

Uploaded by

ae202403428
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Oop Finals

The document outlines key concepts of Object-Oriented Programming, including encapsulation, inheritance, and polymorphism, which enhance code efficiency and reusability. It also discusses data structures like ArrayList, LinkedList, HashMap, and HashSet, highlighting their functionalities and best practices for usage. Additionally, it compares HashMaps and HashSets, detailing their purposes, structures, operations, performance, and appropriate use cases.

Uploaded by

ae202403428
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Object-Oriented Programming Concepts ●​ Best for fast operations​

●​ Encapsulation​
Hides internal details of objects to protect data and simplify code changes.​ ●​ Common in caching, managing sessions, and dictionaries​

●​ Inheritance​ Code Samples


Lets one class use the features of another class, making it easier to reuse code.​ ●​ Sample 1​

●​ 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​

●​ LinkedList​ ●​ Null Handling: Be careful with null keys and values


A list made of connected parts that makes adding or removing items fast. Main Topic: HashMaps VS HashSets
-​ addFirst(): add items at the start Purpose
-​ addLast(): add items at the end ●​ HashMap: Stores key–value pairs​
-​ removeFirst(): remove the first item
-​ getFirst(): get the first item
●​ HashSet: Stores only unique values​
●​ HashMap​
A structure that stores data in pairs (a key and a value).
Structure
-​ put(): store a value with a key ●​ HashMap: Uses entries of keys and values​
-​ get(): get a value using its key
-​ remove(): remove a value using its key ●​ HashSet: Stores only values (no duplicates)​
-​ containsKey(): check if a key exists
Operations
Main Topic: HashMaps ●​ HashMap: Get by key, add key-value, remove, check if key exists​
Introduction to HashMaps
●​ Part of Java Collections Framework​ ●​ HashSet: Add value, remove, check if value exists
Performance
●​ Stores key-value pairs​ ●​ Both give fast average speed for basic operations​

●​ Fast for adding, removing, and retrieving items​ Null Elements


●​ HashMap: One null key, many null values​
Key Features
●​ Unordered: No specific order for elements​ ●​ HashSet: Only one null value allowed​

●​ 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

You might also like