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 8952137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:48:35+00:00 2026-06-15T13:48:35+00:00

Write now I have this class that I would like to be able to

  • 0

Write now I have this class that I would like to be able to save and open using serialization:

public class Region implements Serializable
{
private final int      inputNumberOfColumnsAlongXAxis;
private final int      inputNumberOfColumnsAlongYAxis;
private double         inputDataScaleReductionOnXAxis;
private double         inputDataScaleReductionOnYAxis;

private int            numberOfColumnsAlongXAxis;
private int            numberOfColumnsAlongYAxis;
private int            cellsPerColumn;                // Z-Axis dimension
private float          inhibitionRadius;
private final float    percentMinimumOverlapScore;
private final float    minimumOverlapScore;

I’ve never done object serialization before, so any help would be greatly appreciated!

  • 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-15T13:48:36+00:00Added an answer on June 15, 2026 at 1:48 pm

    The simplest thing you need to do is add a private static field to your class with the name serialVersionUID. For instance:

    private static final long serialVersionUID = 1L;
    

    This is used by the default serialization mechanism to match up class names and formats.

    You can then write instances of your object to an ObjectOutputStream and read them back from an ObjectInputStream:

    Region r = . . .;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(r);
    oos.close();
    ObjectInputStream ois = new ObjectInputStream(
        new ByteArrayInputStream(bos.getBytes()));
    Region r2 = (Region) ois.readObject();
    // voilà - a very expensive clone()!
    

    For more control over your object serialization, you can implement these methods:

    private void writeObject(java.io.ObjectOutputStream out)
         throws IOException
     private void readObject(java.io.ObjectInputStream in)
         throws IOException, ClassNotFoundException;
     private void readObjectNoData() 
         throws ObjectStreamException;
    

    You then have total control over the serialization of your objects. For more info, see the docs on Serializable.

    UPDATE: Strictly speaking, you don’t need to declare serialVersionUID; the runtime environment will calculate one for you automatically if it’s missing. However, the docs have this to say about it (emphasis in the original):

    However, it is strongly recommended that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected InvalidClassExceptions during deserialization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have this public API that my application exposes, allowing customers to write
I would like my class to be: class NumberedString : public Object { public:
I have this GenericRepository class that I intend to use as a base-class for
I would like to be able to read and write (get and set) certain
I am working in Python with an Email() class that I would like to
I have a couple of scenarios that cover this, but I'll write specifically about
I am wondering how you would approach this problem I have two Taxrates that
Right now I have been trying to use Launchpad's API to write a small
Now I have a python project, I write my unit-testing code in many of
I have some complicated, problem to be solved. Now I need to write such

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.