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
What is the difference between array list and vector in java?
List primitive java types?
Explain the difference between arraylist and linkedlist in java?
What is the inheritance?
From the two, which would be easier to write: synchronization code for ten threads or two threads?
Can I declare a class as private?
Is an integer an object?
How many functional interfaces does java 8 have?
What is return used for in java?
What are the high-level thread states in java programming?
What is parsing in grammar?
Can we sort list in java?
Explain reverse a linked list iterative solution in java?
What is difference between module and function?
Program to Find the second largest element in an array.