can write code for serialization ?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

How hashmap works in java?

796


What is a buffer in computer?

716


What is pojo class in java?

727


What are recursive functions?

797


Explain notify() method of object class ?

854


What is constructor and virtual function? Can we call a virtual function in a constructor?

902


Differentiate between overriding and overloading cases?

798


What is difference between class and object in java?

745


What is the map interface in java programming?

780


Explain about static nested classes in java?

819


What is method overloading and method overriding?

759


Can I uninstall java?

795


Is java util regex pattern thread safe?

734


What is the use of jtable?

853


What are inbuilt functions?

746