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 |
There can be a abstract class without abstract methods, but what is the need to declare a class abstract if it doesn't contain abstract methods?
Are static members inherited to sub classes?
What does escaping a character mean?
What is temp in java?
What is scope & storage allocation of global and extern variables? Explain with an example
why static class in java or what is use of static class in java
I want to re-reach and use an object once it has been garbage collected. How it's possible?
Explain the init method?
What are unchecked exceptions in java?
Can we have 2 main methods in java class?
Which package is imported by default?
What are the fileinputstream and fileoutputstream?