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 |
Why is java not 100% pure oops?
Which collection is ordered in java?
difference between String a; and String a=new String();? y do v need to assign memory to the variable?
Explain numeric promotion?
What is the independent variable in an experiment?
What is a numeric literal?
What is method reference in java?
What is constructor
9 Answers Manforce, Tech Mahindra,
What do you mean by exception handling in Java?
Can we define constructor in inner class?
What are streams?
Explain the selection sort algorithm and state its time complexity?