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

How can u increase the heap size in the memory?

0 Answers   Infosys,


What is the difference in between cpp and java? Can u explain in detail?

0 Answers  


How do you check if two strings are equal in java?

0 Answers  


Can an integer be null java?

0 Answers  


What is sorting algorithm in java?

0 Answers  


what is jms? features of jms

2 Answers   CTS,


What is the best definition for data?

0 Answers  


what is difference between prepare stetement and callable starement with example?

1 Answers   CMC,


How do you use nextline in java?

0 Answers  


By what default value is an object reference declared as an instance variable?

1 Answers   Wipro,


Can we compare two strings in java?

0 Answers  


What is the requirement of thread in java?

0 Answers  


Categories