Commit 3a49faa
committed
feat: serialize array of Customer objects to file
WHAT:
- Added `WriteData` class to demonstrate serialization of multiple objects.
- Created an array of `Customer` objects with unique IDs, names, and phone numbers.
- Used `ObjectOutputStream` to serialize and persist the entire array into `Customer2.txt`.
WHY:
- To simplify serialization by writing an entire object array at once instead of looping over individual objects.
- Demonstrates how Java’s serialization mechanism handles arrays of custom objects.
KEY POINTS:
- `Customer` implements `Serializable` so its objects can be persisted.
- `static int count` ensures unique `custID` generation for each new customer.
- `writeObject(list)` serializes the array and all contained objects in one step.
- Output file is binary format, not human-readable, but can be deserialized back to objects.
REAL-WORLD USE CASES:
- Storing customer records in files before saving to a database.
- Exporting application state or session data for later recovery.
- Simple persistence mechanism for desktop or embedded applications.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 9b8b1e0 commit 3a49faa
File tree
2 files changed
+39
-0
lines changed- Section23JavaIOStreams
- Serialisation Storing Data in a File/src
- src/MyJAVA
2 files changed
+39
-0
lines changedLines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
Binary file not shown.
0 commit comments