Commit 9b8b1e0
committed
feat: implement serialization and deserialization with static and transient fields
WHAT:
- Added `StudentFinal` class implementing `Serializable`.
- Demonstrated behavior of `static` and `transient` fields during object serialization.
- Implemented `SerilalizationOutputStreamFinal` to serialize a `StudentFinal` object to file.
- Implemented `SerilalizationIutputStreamFinal` to deserialize and print object details.
WHY:
- To illustrate how Java handles object persistence using `ObjectOutputStream` and `ObjectInputStream`.
- To show that:
- `static` fields are not serialized (they belong to the class, not the instance).
- `transient` fields are skipped during serialization for security or performance reasons.
KEY POINTS:
- `StudentFinal` contains:
- `rollno`, `name`, `avg`, `dept` → serialized normally.
- `Data` (static) → not persisted in file, retains default/class value after deserialization.
- `t` (transient) → not serialized, resets to default value (`0` for int) upon deserialization.
- Serialization: `SerilalizationOutputStreamFinal` writes object state to `Student3.txt`.
- Deserialization: `SerilalizationIutputStreamFinal` reads object back and prints values.
REAL-WORLD USE CASES:
- Transient fields: used to skip sensitive info like passwords, security tokens, or cache references.
- Static fields: excluded since they represent class-wide state, not per-object data.
NOTES:
- Always close streams after use to avoid resource leaks.
- For consistency across JVM versions, explicitly define `serialVersionUID` in serializable classes.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 491cb8c commit 9b8b1e0
File tree
4 files changed
+50
-4
lines changed- Section23JavaIOStreams
- Serialisation Storing Data in a File/src
- src/MyJAVA
4 files changed
+50
-4
lines changedLines changed: 48 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 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 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
Binary file not shown.
Binary file not shown.
0 commit comments