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 java in simple terms?
What is a package in java? List down various advantages of packages.
Difference between final and effectively final ?
List the interfaces which extends collection interface?
What is boolean strategy?
What are the important features of Java 10 release?
Can we access instance variables within static methods ?
What an i/o filter in java programming?
Why singleton pattern is better than creating singleton class with static instance?
What is default constructors?
What is difference between static and abstract class?
Distinguish between a predicate and a function?
What is meant by vector class, dictionary class, hash table class, and property class?
Does java return by reference?
What is int lol?