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
How hashmap works in java?
What is a buffer in computer?
What is pojo class in java?
What are recursive functions?
Explain notify() method of object class ?
What is constructor and virtual function? Can we call a virtual function in a constructor?
Differentiate between overriding and overloading cases?
What is difference between class and object in java?
What is the map interface in java programming?
Explain about static nested classes in java?
What is method overloading and method overriding?
Can I uninstall java?
Is java util regex pattern thread safe?
What is the use of jtable?
What are inbuilt functions?