Unique Book Collection Manager
Course: Object-Oriented Programming in JAVA Lab (BCA39109) | Semester: BCA 3rd Sem
This project demonstrates how to use the Java Collections Framework to store unique objects. While a HashMap can be used as a workaround (by using a concatenated string as a key), this implementation uses a HashSet to fulfill the core Object-Oriented Programming requirement of defining object equality intrinsically.
- HashSet: Utilizing
java.util.HashSetto automatically filter out duplicate entries in a collection. - Object Equality (
equals()): Overriding the defaultequals()method in theBookclass so that Java compares the actual values (Title and Author) rather than the memory addresses of the objects. - Hash Codes (
hashCode()): Overriding thehashCode()method to maintain the strict Java contract: if two objects are equal according toequals(), they must have the same hash code. This is howHashSetlightning-fast duplicate checking works under the hood! - Encapsulation: Keeping class fields
privateand exposing functionality through methods likedisplay().
To run this program, ensure you have the Java Development Kit (JDK) installed on your machine.
- Open your terminal or command prompt.
- Navigate to the directory containing the file.
- Compile the Java code: