Posts

Showing posts with the label Core Java

[Core Java] Serialization & Deserialization

Image
Objects can be flattened and inflated. Objects have state and behavior. Behaviour lies in the class but state lives in each individual object. So what happens when its time to save the state of an object? If you are writing a game, you would need a Save & Restore Game feature. Luckily there is a feature built in java which is to simply freeze-dry/ flatten / persist / dehydrate the object itself to save the state and reconstitute / inflate / restore / rehydrate to get it back.  You have lots of options for how to save the state of your Java Program, and what you will choose will probably depend on how you plan to use the saved state. Here are the options we will be looking at in this chapter.   If your data will be used by only the Java program that generated it:  Use serialization Write a file that holds flattened (serialized) objects. Then have your program read the serialized objects from the file and inflate them back into living, bre...