What would happen if I don't include "implements Serializable?"
public class Student implements Serializable {
private String studentNumber;
private String firstName;
private String lastName;
private ArrayList<Exam> exams;
}
What would happen if I don't include "implements Serializable?"
public class Student implements Serializable {
private String studentNumber;
private String firstName;
private String lastName;
private ArrayList<Exam> exams;
}
Then Student
will behave like a normal class i.e You will not able store the state of the Student
object anywhere
Go through this : https://docs.oracle.com/javase/tutorial/jndi/objects/serial.html
The Student
would not be Serializable, and it will act like a normal class.
Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent storage or streamed across a communication link. The byte stream can then be deserialized - converted into a replica of the original object.
When you want to serialize an object, that respective class should implement the marker interface serializable. It just informs the compiler that this java class can be serialized.
Say you have some objects in memory in the form of references(Java) and pointers (C++) and you want to transmit these objects over a network or store them into a Disk. How would you do that?
Think of solution and hold it in your mind.
There are 2 ways.
First, create a memory dump and save it to the disk or transmit it over the network. But that would require a lot of changes to the memory dump or the memory dump would need exactly the same addresses in memory to that the memory references are not violated.
The second answer is Serialization, convert the data to a string(format like JSON) and then transmit or save it
© 2022 - 2024 — McMap. All rights reserved.
Student
would not beSerializable
. – Priestcraft