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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:17:26+00:00 2026-05-26T20:17:26+00:00

The title tells my need and here the following is code that I’m use:

  • 0

The title tells my need and here the following is code that I’m use:

Test Case

SameObjectDifferentStreams same = new SameObjectDifferentStreams(); 
ObjectOutputStream out1 = new ObjectOutputStream(new FileOutputStream("file1"));
ObjectOutputStream out2 = new ObjectOutputStream(new FileOutputStream("file2"));

out1.writeObject(same);
out1.close();

out2.writeObject(same);
out2.close();

System.out.println("The Original reference is :" + same.toString());

oin1 = new ObjectInputStream(new FileInputStream("file1"));
oin2 = new ObjectInputStream(new FileInputStream("file2"));

SameObjectDifferentStreams same1 = 
    (SameObjectDifferentStreams) oin1.readObject();
System.out.println("The First Instance is :" + same1.toString());

SameObjectDifferentStreams same2 = 
    (SameObjectDifferentStreams) oin2.readObject();
System.out.println("The Second Instance is :" + same2.toString());

Output

The Original reference is :serialization.SameObjectDifferentStreams@9304b1
The First Instance is :serialization.SameObjectDifferentStreams@190d11
The Second Instance is :serialization.SameObjectDifferentStreams@a90653
  • 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-05-26T20:17:27+00:00Added an answer on May 26, 2026 at 8:17 pm

    When you write object to stream you actually serialize it, i.e. write its data only. Then when you read it you read the data and create new object. It is like if you invoke new MyObject() with appropriate constructor arguments. Obviously the new object is created here.

    If you read the same serialized object twice you create new instance twice. These 2 instances are equal, i.e. all their fields are equal, but the references are different, so the expression o1==o2 returns false while (if you implement reasonable equals() method) o1.equals(o2) returns true.

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

Sidebar

Related Questions

i'm having the same issue as the person here , in that i need
The title pretty much says it. I have some methods that need to run
I have the following JQUERY code that I'm expecting to return 3 json results
Here i am sending you my code for simple navigation page...! I am not
So I have a form that I want the user to use to update
(Not sure if this title is the best description...) Hi all. I need a
I hope the title did not mislead you. My problem is the following: Currently
As the title says, I need to write a small program to read data
I'm quite new to .NET programming. I know that .NET programming is 100% object
Hopefully that title isn't too cryptic. What's happening is I have a jQuery AJAX

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.