implementing serialization

As I found on Google that in order to implement Serialization I need to write implements Serializable in the object class and declare a variable like beow.......I dont understand why I need SerialVersionUID..private static final long serialVersionUID = 1L;
[270 byte] By [saranatora] at [2007-10-3 2:23:41]
# 1
declaring Serializable is sufficient. It is not compulsoryto defineprivate static long serialVersionUID = ...Lsince this will be done by the compiler if u don't provide.
PMJaina at 2007-7-14 19:22:40 > top of Java-index,Java Essentials,New To Java...
# 2
OK.....and can I the write the values in a HashMap to a (.ser) file.....I am trying to use ObjectOutput as I have Objects stored in the HashMap
saranatora at 2007-7-14 19:22:40 > top of Java-index,Java Essentials,New To Java...
# 3

> OK.....and can I the write the values in a HashMap to

> a (.ser) file.....I am trying to use ObjectOutput as

> I have Objects stored in the HashMap

u can write the HashMap Object itself. like

Map map = new HashMap();

map.put(..,...);

....

ObjectOutputStream objectStream = new ObjectOutputStream(someOutputStream);

objectStream.writeObject(map);

The HashMap is Serializable.

This can fail if there is any non-transient reference type in the Object tree of the

key or value Object used in the put method

PMJaina at 2007-7-14 19:22:40 > top of Java-index,Java Essentials,New To Java...
# 4

This is how i did it.....will it work.....wanna make sure because HashMap has a lot of data(Objects) and the program takes a couple of hours to run completely.

ObjectOutput out = new ObjectOutputStream(new FileOutputStream("trainingSetNew.ser"));

out.writeObject(map);

out.close();

saranatora at 2007-7-14 19:22:40 > top of Java-index,Java Essentials,New To Java...
# 5
> This is how i did it.....will it work.....The best way to find out is to write up some test code and check.Good LuckLee
tsitha at 2007-7-14 19:22:40 > top of Java-index,Java Essentials,New To Java...
# 6
Lee I did that...........but I cant find the (TrainingSetNew.ser) file that should have been created...the program just ranfine
saranatora at 2007-7-14 19:22:40 > top of Java-index,Java Essentials,New To Java...
# 7

> Lee I did that...........but I cant find the

> (TrainingSetNew.ser) file that should have been

> created...the program just ranfine

Hmmm, that would be a problem then, huh ;-)

You might try calling flush before you call close on your ObjectOutputStream. You might also make sure that you're not ignoring any Exceptions that your code might be throwing.

tsitha at 2007-7-14 19:22:40 > top of Java-index,Java Essentials,New To Java...
# 8
Got it.....now it works thanks guys.......
saranatora at 2007-7-14 19:22:40 > top of Java-index,Java Essentials,New To Java...
# 9
You might post what you did to solve your problem, in case this thread shows up in someone's search results when they're looking for a solution to their problem.
tsitha at 2007-7-14 19:22:40 > top of Java-index,Java Essentials,New To Java...
# 10
had to call flush as I was testing the program over and over again.....the file is created in the main folder where the project is created...
saranatora at 2007-7-14 19:22:40 > top of Java-index,Java Essentials,New To Java...