aspose file tools*
The moose likes Beginning Java and the fly likes serializing java codes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "serializing java codes" Watch "serializing java codes" New topic
Author

serializing java codes

mike saggese
Greenhorn

Joined: Nov 27, 2012
Posts: 8
I could use some help here. I tried to modified the java codes to do what I'm asked to do. here it is

This project consists of three complete and individual subprojects (you need to work in the same subfolder for this assignment). Hints: to write objects with an ObjectOutputStream, the objects classes must implement interface Serializable; coderelated to processing object streams might throw exceptions and these exceptions must be caught.
1) Modify the Employee hierarchy from Figs. 10.4–10.8 to enable serialization of the classes in the hierarchy. Then, modify the application of Fig. 10.9 to output each object in the array employees to a file using object serialization.


2) Modify the application of Fig. 10.9 to read the objects in the file EmployeeData.ser into an array called employees, then output the contents of the array polymorphically as in Fig. 10.9.

3) Since arrays are objects in Java, entire arrays of Serializable objects can be output simply by passing an array’s name to an ObjectOutputStream’s writeObject method. Similarly, an entire array of Serializable objects can be read with a single call to an ObjectInputStream’s readObject method. Modify class OutputEmployees from the above step 1 to write the entire array to the file with a single output statement. Then, modify class InputEmployees from the above step 2 to read the entire array with a single statement.












Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2289
    
  49
That's a lot of code to wade through.
Which parts of the assignment have you completed/are you stuck on and what do you not understand?
Taylor Smolik
Greenhorn

Joined: Dec 04, 2012
Posts: 2
Well without reading all of your code, it sounds like you need to implement serializable in some of your object classes.
You do this in the following format:



You will then import java.io.Serializable;
Also, you should declare a serialVersionUID
(java will usually ask to assign this for you)
Example:

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38878
    
  23
Taylor Smolik wrote: . . .
Also, you should declare a serialVersionUID
. . .
At this stage, adding an SUID simply complicates things. You can get away with omitting the SUID.

You are however right, that every class in sight must implement the Serializable interface. Some classes (eg String) already do.
 
Don't get me started about those stupid light bulbs.
 
subject: serializing java codes