How will you override default serialization mechanism in java
Answers were Sorted based on User's Feedback
Answer / sharmila
Serializable is a marker interface. But you may wish to
control on how an object is serialized instead of using the
default mechanism. In such case add implementations of the
readObject() and/or writeObject() methods to the class being
serialized and override default serialization mechanism.
Also, instead of using Serializable interface,
Externalizable interface can be used
| Is This Answer Correct ? | 4 Yes | 3 No |
you can inplements the Serialization interface for those
class you want to serailize
its marker interface its haven't any behaviour
but it indiacte that particular class is serializable
you can read and write particular object to convert in a
byte.
class Amit implements Serializable
{
Amit()
{
}
}
class B
{
public static void main(String []args)
{
Amit a = new Amit();
try{
}
catch{IoExcepton e)
{
}
try{
FileIntputStream f = new FileIntputStream("apoorva.txt")
OjectIntputStream o = new ObhjctInputStream(f);
o.ReadObject();
}
catch(IoException e)
{
}
}
thanks amit singh
amitsing2008@gmail.com
| Is This Answer Correct ? | 0 Yes | 1 No |
How do you relate a Interface to a Class? Tell me in Detail?
What is the common usage of serialization? What exceptions occur during serialization?
What is defined as false sharing in the context of multithreading?
Write the algorithm to check the number non-leaf nodes in a tree.
Is there any limitation of using inheritance?
What is the ResourceBundle?
2 Answers Elementus Technologies,
What is variable and rules of variable?
What is the difference between member variables initialization and assignment in a constructor?
Can we have multiple public classes in a java source file?
Can subclass overriding method declare an exception if parent class method doesn't throw an exception?
What is the base class of all exception classes in java?
Where we write javascript code in html page?