Wednesday, February 24, 2016

What is Serialization in java ?

Serialization is a type of mechanish or process in java using which an object state can be saved in a stream of bytes and its a platform independent so object serialized in one platform can be deririalize in anothe platform.

UseCase
When an object is converted into Bytes Stream then that object can be 
Serialized object can be Stored into database
Serialized object can be stored/write into file
that object can be send over the network
that object can be stored into memory

In java serializable interface is a marker interface there is no method in that interface.
When you want any class object to be serialized then you need to implement the serializable interface.
whenever any object is being serialized then all the member of the object is serialzed except transient and static variables.

also take a look at when to use Volatile ? and  when to use transient ? in java



What is transient in Java ?

About transient 
transient is a keyword which is used with the member variable of a class to exclude a particular variable from the serialization process (In serialization an object state is saved in bytestream by JVM).

One cannot use the transient keyword with the static variable.

transient variable initialized with the default value during de-serialization
(In Deserialization process object state is recovered by JVM except the static and transient variablers)

also take a look at the what is volatile keyword in java

Advantage
many times as a developer we do not want to serialize some members of object at that one can use the transient keyword and it gives us flexibility in this case as per our requirement.

UseCase
may times some variables value is dependent on other variable, means we can gain value of particular variable from other variables value at that time we can exclude particular variable from being serialization process.
sometimes we use some members of class just for logs purpose those variables also no need to be serialize.

What is volatile keyword in java ?

volatile is a keyword in java it is used to indicate java compiler and java thread that do not cache the value of the variable preceded with the volatile keyword and all time read the volatile variable's value from the main memory. 

So whenever you want read and write operation to be atomic on any variable then declare that variable with volatile keyword.

also take a look at what is transient in java

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...