• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialization in java  RSS feed

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is Serialization is handled by JVM or we have to handled it by using ObjectOutput Stream object.For Ex.

import java.io.*;
import java.util.*;
class SerializeTest

{
public static void main(String[] args)
{
List la = new ArrayList();
la.add(32454);
try{
ObjectOutput out = new ObjectOutputStream(new FileOutputStream("filename.ser"));
out.writeObject(la);
out.close();
}catch(Exception e){System.out.println(e);}
}
}

In the above code i am using ObjectOutputStream object and inside that i am passing the FileOutputStream object, and i am able to serialize the arraylist.
I just want to know that is this the only way to serialize the object or JVM by default provides this functionality i.e., suppose that i made a class and that class implements Serializable interface.So does the JVM will handle the serialization internally and provides implementation for ObjectOutputStream OR we have to use it as i have used in the above code.
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JVM just interprets byte codes that came from compiling some class or other. In your case the class is ObjectOutputStream. You're doing it just right.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!