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 does a for loop work java?
What is the purpose of encapsulation?
Is 0 a prime number?
What is operator overloading. Is it is supported in java?
What is object-oriented programming?
How can we create an immutable class in java?
Why destructor is not used in java?
What is the reason behind using constructors and destructors?
Explain the overview of UDP messaging.
Can we override a variable in java?
How do you clear an arraylist in java?
What are java packages? What is the significance of packages?
What are 3 data types?
What is sortedmap interface?
What does provide mean construction?