Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8821769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:56:08+00:00 2026-06-14T05:56:08+00:00

I understand that serialization is a quick way to save instances of objects, including

  • 0

I understand that serialization is a quick way to save instances of objects, including all variables within the objects, excluding static references and those marked with the transient keyword.

I’m not very good with I/O and my application has about 50 classes of which there are three distinct different objects (which contain objects within them).

For example, I have an Animal Class, Employee Class, Vehicle Class. All which contain instance objects, at run time, which contain their own subclasses, methods, etc.

My question is, what is the easiest way to save all this information with Serialization? I have discussed this problem with my professor and he suggested something like an encompassing class “Data.class” that has it’s “hands” in everything, and then Serializing that. Which would end up saving every object it references to the .ser file.

I thought about making the “Data.class” and then making all my 50 classes, extend Data.
and then having my save method do something like

public void saveData(){
       Data myData = new Data()
try
      {
         FileOutputStream fileOut =
         new FileOutputStream("Data.ser");
         ObjectOutputStream out =
                            new ObjectOutputStream(fileOut);
         out.writeObject(myData);
         out.close();
          fileOut.close();
      }catch(IOException i)
      {
          i.printStackTrace();
      }
}

However, I can’t seem to get this to work. I believe it is because I am creating a blank instance of Data which contains only default values for all the subclasses. I am calling the function when I do intend to save (after all values in their corresponding objects are filled), but I am doing something wrong and can’t figure out what.

Any help would be greatly appreciated. Surely I don’t have to manually serialize every single instance of the three different types of objects? It is over 300 and I’d prefer not to do that.

Also, I did give Data a serialVersionID and implement the serializable interface for Data.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:56:10+00:00Added an answer on June 14, 2026 at 5:56 am

    Make sure all your classes implements the Serializable interface and this Data class has the methods to serialize/deserialize your Animal, Employee, Vehicle and other classes.

    You can do this easily by having a single method saveData(Serializable serializable, String fileName). This would be a skeleton for your needs (based in your actual code):

    public class Data {
    
        public void saveData(Serializable serializable, String fileName) {
            try {
                FileOutputStream fileOut = new FileOutputStream(fileName);
                ObjectOutputStream out = new ObjectOutputStream(fileOut);
                out.writeObject(myData);
                out.close();
                fileOut.close();
            } catch(IOException i) {
                i.printStackTrace();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that the best way to develop a free and paid version of
I understand that you generally serialize objects for data persistence using the NSCoder protocol
With Java Serialization, I understand that when a field is marked as transient, it
Why does the JSON serialization not work for datetime objects? As I understand JSON
I understand that you can set the Serialization Mode = Unidirectional to allow data
I understand how serialization works and was wondering if there is a way to
I understand that I can't extend static classes in C#, I don't really understand
I understand that: '\n' // literally the backslash character followed by the character for
I understand that JVM and CLR were designed as stack-based virtual machines. When JIT
I understand that the em measurement is a relative unit for font-size, relative to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.