What happens if I do not implement Serializable when using Hashmap

What happens if I do not enable "implements Serializable?"

public class Student implements Serializable { private String studentNumber; private String firstName; private String lastName; private ArrayList<Exam> exams; } 
+6
source share
3 answers

Then Student will behave like a regular class i.e. you cannot save the state of the Student object somewhere

Go through: https://docs.oracle.com/javase/tutorial/jndi/objects/serial.html

+6
source

Student will not be Serializable, and it will act like a regular class.

Serialization is the conversion of an object into a series of bytes so that the object can be easily stored in persistent storage or transmitted over a communication channel. Then the stream of bytes can be deserialized - converted to a replica of the original object.

When you want to serialize an object, this class must implement a serializable token interface. It simply tells the compiler that this Java class can be serialized.

More details

+3
source

Let's say you have some objects in memory in the form of links (Java) and pointers (C ++), and you want to transfer these objects over the network or save them to disk. How do you do this?

Think about the decision and keep it in your mind.

There are two ways.

First, create a memory dump and save it to disk or transfer it over the network. But this will require many changes in the memory dump, or a memory dump will require exactly the same addresses in memory that the memory links will not be broken.

The second answer is serialization, converting data to a string (JSON format), and then transferring or saving

0
source

All Articles