can write code for serialization ?



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

Post New Answer

More Core Java Interview Questions

How do you access command-line arguments within the code?

1 Answers   Flextronics, Hexaware,


how to run ecllipse with jettyserver for windows environment using batch file

1 Answers  


What method is used to compare two strings ?

4 Answers  


What is native code?

1 Answers  


What is a map? What are the implementations of map?

1 Answers  


In how many ways we can do exception handling in java?

1 Answers  


What do you mean by light weight and heavy weight components?

1 Answers  


How do you convert string to int in java?

1 Answers  


Can a static method be overridden in java?

1 Answers  


Why we need to serialize the object

11 Answers   CTS, Geometric Software,


What is a local block?

1 Answers   Global Logic,


difference between String a; and String a=new String();? y do v need to assign memory to the variable?

2 Answers  


Categories