can write code for serialization ?
Answer / 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 |
Does treeset allow null in java?
How to prevent to create multiple objects of a java class?
How do you sort arrays in java?
What is definition and declaration?
What is the difference between the continue and break statement?
What is the difference between assignment and initialization?
What are the differences between getting and load method?
What are the 5 types of research methods?
What string is utf8?
What is parsing in grammar?
What is the default size of set in java?
What are the differences between checked exception and unchecked exception?