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 |
How to stop a thread in java? Explain about sleep () method in a thread?
Does chrome use java?
What is an enumeration class?
How to sort a collection of custom Objects in Java?
What are teh sub-classes of a component class?
Explain about field hiding in java?
Is boolean a wrapper class in java?
Can a class have an interface?
Infinite loop using while ?
What is package private scope in java?
Which number is denoted by leading 0x or 0x in java?
What is ctrl m character?