Skip to content

Commit 491cb8c

Browse files
committed
docs: add notes on serialization and file permission handling in Java
WHAT: - Documented core concepts of object serialization and deserialization. - Added explanation of the `Serializable` interface and behavior of `transient` and `static` fields. - Summarized file permission methods available in the `File` class (`canRead`, `canWrite`, `canExecute`). - Included example usage for checking and modifying file permissions. WHY: - Serialization is essential for persisting and transmitting objects (e.g., saving to files, sending over a network). - File permission methods are critical for secure file handling and preventing unauthorized access. - Developers need a concise reference for these common Java I/O practices. KEY POINTS: - Serialization: - Converts an object into a byte stream. - Deserialization reconstructs the object from the stream. - `transient` fields are skipped, `static` fields are not serialized. - File Permissions: - `canRead()`, `canWrite()`, `canExecute()` → check existing permissions. - `setReadable()`, `setWritable()`, `setExecutable()` → modify permissions. - Behavior is OS-dependent and subject to Java Security Manager restrictions. REAL-WORLD USE CASES: - Serialization: Storing user sessions, caching objects, or transmitting data between distributed systems. - File Permissions: Enforcing read-only configuration files, restricting log file edits, or controlling executable scripts. NOTES: - Always ensure serialVersionUID is defined in Serializable classes for version consistency. - Permission methods may succeed or fail depending on the OS-level policies, not just Java code. Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent e9e5eea commit 491cb8c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Section23JavaIOStreams/Serialisation Storing Data in a File/src/Serialisation.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ The method canRead() of the File class is used to check if a file is readable.
1111
This method returns a boolean value indicating whether the application can read the file denoted by the File object.
1212

1313
Key points about file permissions in Java:
14+
1415
1. canRead(): Checks if the file is readable.
1516
2. canWrite(): Checks if the file is writable.
1617
3. canExecute(): Checks if the file is executable.
1718
4. setReadable(), setWritable(), setExecutable(): Methods to change file permissions.
1819

1920
Example usage:
20-
```java
21+
2122
File file = new File("example.txt");
2223

2324
if (file.canRead()) {
@@ -35,10 +36,9 @@ if (file.canWrite()) {
3536
// Change permissions
3637
file.setWritable(true);
3738
file.setReadable(true, false); // true for all users, false for owner only
38-
```
3939

4040
It's important to note that these methods work within the constraints of the underlying operating system
4141
and the Java Security Manager.
4242

4343
The actual ability to read, write, or execute a file may depend on factors beyond just the file permissions,
44-
such as overall system security policies.
44+
such as overall system security policies.

0 commit comments

Comments
 (0)