can write code for serialization ?



can write code for serialization ?..

Answer / bharat shivram

import java.io.*;
public class SerializationDemo {
public static void main(String args[]) {
// Object serialization
try {
MyClass object1 = new MyClass("Hello", -7, 2.7e10);
System.out.println("object1: " + object1);
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object1);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Exception during serialization: " + e);
System.exit(0);
}

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More Core Java Interview Questions

What do you mean by composition in java?

0 Answers  


What is an exception? difference between Checked and Unchecked exception in Java

0 Answers   SkillGun Technologies,


Can we override the private methods?

0 Answers  


can any one send me the example program of immutable class?

2 Answers   Arfin, TCS,


How listener identify that the event came from a particular object?

0 Answers  






What are the main differences between the java platform and other platforms?

0 Answers  


what are synchronized methods and synchronized statements? : Java thread

0 Answers  


What is difference between variable declaration and definition?

0 Answers  


What is yield () in java?

0 Answers  


What for read() function?

3 Answers  


what are literals in java?

2 Answers  


What is the function of static in java?

0 Answers  


Categories