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

Why is java not 100% pure oops?

0 Answers  


Which collection is ordered in java?

0 Answers  


difference between String a; and String a=new String();? y do v need to assign memory to the variable?

2 Answers  


Explain numeric promotion?

0 Answers  


What is the independent variable in an experiment?

0 Answers  






What is a numeric literal?

0 Answers  


What is method reference in java?

0 Answers  


What is constructor

9 Answers   Manforce, Tech Mahindra,


What do you mean by exception handling in Java?

0 Answers   Atos Origin,


Can we define constructor in inner class?

0 Answers  


What are streams?

0 Answers  


Explain the selection sort algorithm and state its time complexity?

0 Answers   Flextronics,


Categories