Commit 03d35f9
committed
docs: Add comparison of toString(), printf(), and custom printDetails() usage
WHAT the file contains:
- A comparison table outlining three different approaches for object display in Java:
1. **toString()**
2. **printf()**
3. **printDetails()**
- Each row lists pros and recommended usage scenarios.
WHY this matters:
- Helps decide the best method for printing/debugging object information.
- Provides clarity between reusable overrides (`toString()`), formatting needs (`printf()`), and explicit helper methods (`printDetails()`).
- Useful as a quick reference for beginners learning object display strategies.
HOW it is structured:
1. Markdown table with three columns:
- **Method** → name of the approach.
- **Pros** → advantages of each method.
- **When to Use** → suggested scenarios for applying them.
2. Highlights `toString()` as the **best general practice** due to reusability.
Tips & gotchas:
- Overriding `toString()` is standard, but avoid exposing sensitive data in its output.
- `printf()` requires format specifiers (`%s`, `%d`, etc.) and works best for tabular or aligned output.
- `printDetails()` (custom void method) is clear but less reusable than `toString()`.
Use-cases:
- Documentation for Java beginners deciding how to output object state.
- Quick guide for interview preparation or coding best practices.
- Can be included in project guidelines to standardize debugging practices.
Short key: docs-object-display-methods-comparison.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 3d0aae8 commit 03d35f9
File tree
1 file changed
+7
-0
lines changed- Section10Methods/Methods 2.O/src
1 file changed
+7
-0
lines changedLines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
0 commit comments