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 |
Can a constructor be made final?
What are the different ways to handle exceptions?
What is an abstract class?
How do you create a method in java?
What is contractor means and methods?
Tell me the Importent classes in net package?
Is list ordered in java?
What are synchronized methods and synchronized statements in java programming?
Does java support multi dimensional arrays ?
What is a class in java?
what is meant by multicast?
Why we use static and synchronized in method for single thread model example: public static synchronized add(){}