How will you override default serialization mechanism in java

Answers were Sorted based on User's Feedback



How will you override default serialization mechanism in java..

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

How will you override default serialization mechanism in java..

Answer / amit singh

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

Post New Answer

More Core Java Interview Questions

Explain constructors and types of constructors in java.

0 Answers  


Can a static class have a constructor java?

0 Answers  


Is array primitive data type in java?

0 Answers  


In what type of containers, Border layout is a default layout?

3 Answers  


Is array dynamic in java?

0 Answers  






What do you mean by singleton class in java?

0 Answers  


what is java bean?where can we use it?

12 Answers   TCS,


int a=1; float b=1.0; System.out.println(a==b);

13 Answers   CTS, Honeywell, McAfee,


how to print the below in java? * * * * * * * * *

2 Answers  


which class is the wait() method defined in? : Java thread

0 Answers  


Where can I find data structures question and answers with comprehensive working code written in Java

0 Answers   Amazon,


What is dot operator?

0 Answers  


Categories