• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

serializing java codes

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.












 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
They worship nothing. They say it's because nothing is worth fighting for. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic