Serializable is an interface in Java which is implemented by classes that will be having code that will read or write an object into bits that can be stored on disk or can be sent over the network. Where exactly do you need clarity?
Serializable is an interface in Java which is implemented by classes that will be having code that will read or write an object into bits that can be stored on disk or can be sent over the network. Where exactly do you need clarity?
Thanks r035198x and heat84, This quote gets me some idea.
But i don understand the following...
Serializability of a class is enabled by the class implementing the java.io.Seriali zable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.
Thanks r035198x and heat84, This quote gets me some idea.
But i don understand the following...
Serializability of a class is enabled by the class implementing the java.io.Seriali zable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.
Thanks,
P.Jerald.
Objects can be serialized if their classes or super classes were specified as implementing the serializable interface. Which part do you not understand there then?
Actually what i am trying to know the term "serialize" ..
"Objects are serialized with the ObjectOutputStr eam and they are deserialized with the ObjectInputStre am."
And what the above says..
Thanks,
P.Jerald
"Serializab le" means you can save and load the whole object, for example to a file on a disk, or to a database, with just a single command and without going into its internals.
"Stream" means, you save or load the data to a disk, to a database or to whatever external device you want. It depends on the type of stream.
For example you have an object that stands for a company. Inside you have a list of employees and a list of rooms. Each employee is an object that has a name, salary, etc.. Each room consists of a list of furnitures. So you see you have a rather complex object. Without serialization, you must loop through the data of your company object and save all the employees, rooms etc., one by one. And when saving an employee, you must write code to save its name, salary etc.. You would do that in some hundred lines of code. And whenever your structure changes, you have to rewrite your code. But with serialization (that means if all components implement the serialized interface), you can save the whole structure with a single command. You can also read an object with a single command.
No need anymore to write all these lines of code. If your structure changes, no need to change any single line regarding saving or loading. But there is one drawback: if your structure changes, you cannot read an old object into a new structure. Usually you read in an old object and copy the data over into a new object.
"Serializab le" means you can save and load the whole object, for example to a file on a disk, or to a database, with just a single command and without going into its internals.
"Stream" means, you save or load the data to a disk, to a database or to whatever external device you want. It depends on the type of stream.
For example you have an object that stands for a company. Inside you have a list of employees and a list of rooms. Each employee is an object that has a name, salary, etc.. Each room consists of a list of furnitures. So you see you have a rather complex object. Without serialization, you must loop through the data of your company object and save all the employees, rooms etc., one by one. And when saving an employee, you must write code to save its name, salary etc.. You would do that in some hundred lines of code. And whenever your structure changes, you have to rewrite your code. But with serialization (that means if all components implement the serialized interface), you can save the whole structure with a single command. You can also read an object with a single command.
No need anymore to write all these lines of code. If your structure changes, no need to change any single line regarding saving or loading. But there is one drawback: if your structure changes, you cannot read an old object into a new structure. Usually you read in an old object and copy the data over into a new object.
Serialization simply means writing an object's state to a squence of bytes (and reading those bytes later into an object).
The main benefit is actually that objects can persist in memory even after the program(or VM) terminates.
Serialization simply means writing an object's state to a squence of bytes (and reading those bytes later into an object).
The main benefit is actually that objects can persist in memory even after the program(or VM) terminates.
Thanks, chaarmann,heat8 4 and r035198x. Thanks a lot.
regards,
P.Jerald.
Comment