Hi all,
I'm learning Serialization in JAVA .
I learned that "an array object is serializable as long as the things in the array are serilizable" .
I just need a clarification on that statement .
To understand that concept I myself coined a simple program .
Here it's :
import java.io.*;
public class Saveit {
public static void main(String[] args) {
int[] arr ={10,20,30,40,50};
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(new File("saveInt.ser")));
os.writeObject(arr);
os.close();
}catch(IOException ex) { ex.printStackTrace() ; }
arr =null;
try {
ObjectInputStream is = new ObjectInputStream(new FileInputStream(new File("saveInt.ser")));
int[] restore = (int[]) is.readObject();
for(int i:restore)
System.out.println(i);
is.close();
}
catch(Exception ex) { ex.printStackTrace(); }
}
}
What I understood from that statement and program are follows :
1.We don't need to explictly implement Serializable for to save arrays
2.If we try to serialize an array it's contents should also be serializable(for objects only)
3.Primitive types are serializable by default if it is an array.
please clarify me what I understood is correct or not and also anything else I should know or missed.
Did I have misunderstood something ?
Thanks in advance