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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:38:47+00:00 2026-06-10T10:38:47+00:00

When I read the source code of JDK 6.0 I found these two methods

  • 0

When I read the source code of JDK 6.0 I found these two methods in ArrayList. You see they are both private. But after searching, I didn’t find any other methods calling either of them. I also considered the native methods, but still couldn’t find any. These two methods seem to deal with the IO, but they are never called.

So, my question is, how do they work? Is there any other way to call private methods?

/**
 * Save the state of the <tt>ArrayList</tt> instance to a stream (that is, serialize it).
 */
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException;

/**
 * Reconstitute the <tt>ArrayList</tt> instance from a stream (that is, deserialize it).
 */
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException;
  • 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-10T10:38:48+00:00Added an answer on June 10, 2026 at 10:38 am

    These two methods are used in serializable class to customize the serialization (aka Customize the Default Protocol).

    Text from article:

    There is, however, a strange yet crafty solution. By using a built-in
    feature of the serialization mechanism, developers can enhance the
    normal process by providing two methods inside their class files.
    Those methods are:

    1. private void writeObject(ObjectOutputStream out) throws IOException;
    2. private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException;

    Notice that both methods are (and must be) declared private, proving
    that neither method is inherited and overridden or overloaded. The
    trick here is that the virtual machine will automatically check to see
    if either method is declared during the corresponding method call. The
    virtual machine can call private methods of your class whenever it
    wants but no other objects can.

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

Sidebar

Related Questions

is there anyone have read the source code of dtl in c++? I found
I am trying to read Android source code to learn about binder, but I
I read larbin source code recently. But I have a doubt. I the global.h
I read some source code of ZenTest but didn't find where it is implemented.
Sometimes, I read the source code, found that the module is loaded manually like
I want to read a specific line from an html source code. Im storing
In my open-source plain C code I use this simple structure to read and
I've read various sources but I'm unsure how to implement them into my code.
Is there a way that a JavaScript function can read the JavaScript source code
I am studying web2py. I read example open source code. In one application (storpy),

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.