How ObjectInputStream.readObject() works??

Below is Test.java, some codes on simple serialization operations (copied from a book.) A "Blip1" object is created, serialized to a file, then deserialized back from the file. Everything works fine!!
My question is, why does the last line work, "b1 = (Blip1)in.readObject();" ?
I mean, ObjectInputStream is part of [package java.io], how can we create a "Blip1" object of [package anypackage] while we are inside [package java.io]?? Am I missing something fundamental?
I thought this ObjectInputStream.readObject() is based on Reflection, that is, ObjectInputStream.readObject() created the "Blip1" object based on the class name. So I wrote Creator.java (see below) and the result was an IllegalAccessException --- we cannot create a "Blip1" object while we are inside another package. This shows that ObjectInputStream.readObject() is not really based on Reflection(??)
How does ObjectInputStream.readObject() work??
//Test.java
package anypackage;
class Blip1 implements Externalizable {
  public Blip1() {System.out.println("Blip1 created");}
  public void writeExternal(ObjectOutput out) throws IOException {}
  public void readExternal(ObjectInput in)
    throws IOException, ClassNotFoundException {}
public class Test {
  public static void main(String[] args)
  throws IOException, ClassNotFoundException {
    System.out.println("Constructing objects:");
    Blip1 b1 = new Blip1();
    ObjectOutputStream o = new ObjectOutputStream(
      new FileOutputStream("Blips.out"));
    System.out.println("Saving objects:");
    o.writeObject(b1);
    o.close();
    // Now get them back:
    ObjectInputStream in =
      new ObjectInputStream(
        new FileInputStream("Blips.out"));
    System.out.println("Recovering b1:");
    b1 = (Blip1)in.readObject();
//Creator.java
package anyotherpackage;
import java.util.*;
public class Creator{
  Object o;
  public Creator(){
    try{
      Class c = Class.forName("anypackage.Blip1");
      Object o = c.newInstance();
    } catch (Exception e){
      System.out.println(e);
  public static void main(String[] args){
    Creator c = new Creator();
}

As far as i understand the ObjectInputStream.readObject() create object by recursively building the memory owned by the object, obviously object Ctor is not called (otherwise serializeable classes were forced to have empty Ctor).
It goes like this -
1)when object implements Serializable interface its stream hold description of the the object memory (for each datamember we will have something like offset,datamember type, and streamed datamember), ObjectInputStream.readObject build the datamembers recursively (recursion is stopped when we have primitive type datamember)
2)when object implements Externalizable interface the programmer is responsible to stream object's datamembers to the ObjectOutput and to read them from the ObjectInput, ObjectInputStream is responsible to create an empty object for you
anyway no Ctors are involved

Similar Messages

  • How does serialization work.......!!

    As Serializable interface is an MARKER interface and does not have any methods or field. Then how does a class implementing Serializable interface is automatically serialized(or the object is converted into bytestream).
    Is it that, JVM does know what to do with a serialized object.
    If this is the case, can I have a MARKER interface of my own, for a particular functionality.
    with regards,
    SHIRISH

    As Serializable interface is an MARKER interface and
    does not have any methods or field. Then how does a
    class implementing Serializable interface is
    automatically serialized(or the object is converted
    into bytestream). They are not serialized automatically. There are methods available for that - ObjectInputStream.readObject() and ObjectOutputStream.writeObject().

  • How do I work with FK in a data profile?

    Hello People:
    I am new in OWB tools and I have many doubts. Therefore, I would like to know if anyone can guide me a bit with the theme of FK and profiles.
    How do I work with FK in a data profile?
    If I have a table that has a FK to most of the tables, because it is like a parent table. What should I do to have that FK in the profile?
    e.g.
    - Table 1 FK Table 2
    - Table 1 FK Table 3
    - Table 1 FK Table 4
    - Table 1 FK Table 5
    - Table 1 FK Table 6
    - Table 2 FK Table 7
    - Table 2 FK Table 8
    - Table 8 FK Table 9
    You should have a data profile with each table or a data profile for all related tables?
    If I am all in a single profile, that it would have no problem but I would only slow every time that I have to add a new table, but if I got separated, I can not use the FK? What is the solution that will give this problem?
    e.g. PROFILE GENERAL
    - Table 1
    - Table 2
    - Table 3
    - Table 4
    - Table 5
    - Table 6
    - Table 7
    - Table 8
    - Table 9
    OR
    PROFILE 1 -> - Table 1
    PROFILE 2 -> - Table 2
    PROFILE 3 -> - Table 3
    PROFILE 4 -> - Table 4
    PROFILE 5 -> - Table 5
    PROFILE 6 -> - Table 6
    PROFILE 7 -> - Table 7
    PROFILE 8 -> - Table 8
    PROFILE 9 -> - Table 9
    OR
    PROFILE R -> Table 1 / Table 2
    PROFILE S -> Table 1 / Table 3
    PROFILE T -> Table 1 / Table 4
    PROFILE U -> Table 1 / Table 5
    PROFILE V -> Table 1 / Table 6
    PROFILE W -> Table 2 / Table 7
    PROFILE X -> Table 2 / Table 8
    PROFILE Z -> Table 8 / Table 9
    Thank you very much for your help!
    Best regard!

    Any idea, please?

  • How does this work?

    This is not a complaint, but a confused sigh of admiration. I've got an email account at the university where I teach. When I got my iBook, it took me a while, and a few conversations with IT at the school, to get this account working in the Mail application. (Since I have a Verizon DSL at home, I had to include that SMTP as the outgoing server.) Anyway, I synched this mail account (along with my AOL and .Mac accounts) onto the iPhone, and it works perfectly, both incoming and outgoing. I didn't have to change any of the settings. I thought I was computer savvy, but I can't wrap my mind around this. It seems like magic. How does it work?

    The sync process with iTunes transfers the email account settings (for your chosen accounts via your iPhone sync preferences) from the Mail application on your Mac to the iPhone's email application.
    The iPhone is running OS X and the iPhone's email client can be considered a mobile version of the Mail application.

  • My iPhone was stolen and I have contacted the police who are using the meid number to locate.  How does this work and what are my chances of getting the phone back?

    My iPhone was stolen.  I used Find My iPhone app to lock it and display a message.  The phone has not connected to the internet to locate it.  I contacted the police and they have taken my meid number.  How does this work and what are my chances of getting the phone back?  Are there other ways the theif can use it.  I was told once they put in a new sim card and use it, whatever software the police have, it will show up.

    Honestly? In the US (I can't speak to other countries, though I doubt it works much differently in a lot of the world) The police took your report and filed it either in their computers or, on paper. They will now not think of this again. The only time it will cross anyones mind is if, in the course of entering information into evidence about items recovered or seized at a crime scene, the serial number of an iPhone that was found/seized happens to match yours, in which case you will be contacted.
    The police in the US can and will do nothing to 'blok' the phone and it's not worth their time to try and locate it unless you know for a fact that it was stolen by a big time drug lord, master criminal, or some other such prime target and they can get a court order to track the location of the phone in order to locate this individual for your own purposes.  If they do that, they'll probably keep him under surveilance for a year or so before they act.
    Basically, the police don't care about your phone. If they find it, they will give it back to you. They are not, however, going to go looking for it. They have better things to do.
    I'm sorry, but that's the way it is.

  • Was told a USB device would create a PDF automatically from the data contained within when plugged into my USB port. Doesn't seem to work. How does this work and how can I fix the device I received?

    Acrobat is not on the USB device - only Adobe Reader needed on the PC. How does this work? How can I fix this device if at all?

    You need to ask the people who sold it to you. Doesn't sound like it has anything to do with Reader.
    However, you should be wary of devices that automatically try to open files when plugged in. They can also infect your computers with all kinds of viruses or malware.

  • HT2357 So how does this work on Mountain Lion? I cannot seem to ignore the iTunes 11 updates, which now seem to appear every 5 minutes!!

    So how does this work on Mountain Lion? I cannot seem to ignore the iTunes 11 updates, which now seem to appear every 5 minutes!!

    Fantastic!  Didn't work at first so restarted App store and tried again.  This time it asked 'ignore update'.  All gone!

  • TS1425 My co worker has given me his iPod to take home and transfer his music to my laptop, however, I am unable to access his music to download it to my computer.  How does this work?

    My co-worker has given me his iPod to take home and transfer his music to my laptop, however, I am unable to access his music to download it to my computer.  How does this work?

    You need to transfer the iTunes Library from the most recent backup you made before the hard drive was replaced.
    You can't transfer the full iTunes Library from the iPad back to iTunes.
    There are third-party Windows applications that will transfer data from an iOS device, but they don't re-create the iTunes Library exactly as it was before.

  • I have a macbook air and I can't cut and paste in itunes.  The right clic does not work. How can I work this out?

    I have a macbook air and I can't cut and paste in itunes.  The right clic does not work. How can I work this out?

    Great tip Stephen!!
    I was so frustated from this issue that I used to use Windows iTunes for mass editing info, adding Lyrics etc and then transfering songs to Mac. This tip has alleviated my pain!!
    Thanks for the tip. This question should be tagged as answered.

  • After upgrading to Photos, how can I work on a Book Project from another apple device?

    After upgrading to Photos, how can I work on a Book Project from another apple device?

    I'm not sure I understand what you are asking, but on the device/Settings, do you have iCloud and Photos sync turned on?

  • My wife and I have separate Ids but all our music is in one library. How will this work with iCloud?

    My wife and I have separate Ids but all our music is in one library. How will this work with iCloud? i'm trying to download past purchases from her id, but itunes is saying that I can't because the computer is associated with my apple id. Can I associate the computer with both ids for the purpose of identifying all of our music with both or just one of our ids? Is there a good way to do this? I'm sure we're not the only people with this problem...
    Using 2 iphone 3gs, ipad, mac mini, appletv, itunes for windows, macbook, and imac.

    iTunes- How to share music between different user accounts on a single computer
    You cannot merge two separate libraries across user accounts. Photos does not have the function of merging different Photos.library files. If you have Aperture then you can merge the two before migrating over to Photos.

  • HT204053 My husband and I both have iPhones but we only have one iPad. We use the same apple ID because we also share the same email address. How would this work with iCloud because we don't share the same contacts?  Thanks Elainecontacts

    My husband and I both have an iPhone and we share an iPad. We also share the same email address so how would this work with iCloud because we don't share all the same contacts?
    Thanks

    An icloud account is designed to be used by one user.  That user can have all his/her devices synced with the same Apple data (email, contacts, calendars, notes, reminders, etc.) .  When two people use the same account, then problems usually occur when one user edits data that the other user doesn't want changed on their device.  You can continue sharing the same ID for the itunes account in order to share the purchased music, apps, etc.  itunes accounts and icloud accounts are different.
    It's by far better that each user has his/her own icloud account.

  • How does Remote work with Apple TV?

    How does Remote work with Apple TV?
    1. Does Remote, "Play" the music that resides on your iPod Touch>Apple TV>Home Speakers.
    OR
    Does Remote "Control" the music that resides on Apple TV HD>Home Speakers.
    (If so... say you have a iPod Touch that only holds 8GB's but your music collection on your Apple TV exceeds that amount.
    Will Remote still "Control" the larger music collection on Apple TV or your computer?)
    2. Will iPod Wifi work on a patio outside a home to control Apple TV inside the home?
    thank you in advance, Tom

    Remote is a way to control iTunes on either your computer or Apple TV using a WiFi connection. See this article for complete instructions.

  • ICloud Photo Library (beta) - how does it work?

    8.0.2 has an option to enable iCloud Photo Library (beta), I am trying to understand how it works before I turn it on...
    The description says it will auto-upload the entire iPhoto Library to iCloud so other devices that can access these photos by using the same Apple ID. It also has sub-option to keep original photo or keep optimized photo on the device. So questions:
    1. This feature seems to do what Photo Stream does, will new taken photos be auto-sent to iCloud and Photo Stream?
    2. Does iCloud Photo Library count iCloud storage?
    3. Those albums synced with iTunes, will they be uploaded to iCloud Photo Library, and no longer sync with iTunes? Will they be deleted from devices? Will the iTunes Photo Sync selections be disabled?
    4. Here "iPhoto Library" refers to the photo library on devices only, or it includes the Photo Library on computer? My Mac iPhoto/Aperture also signs in the same Apple ID, will those photos on my Mac be auto-uploaded to iCloud?
    5. Presently I sync selected photos to devices via iTunes, if iTunes Sync is disabled after enabled iCloud Photo Library, how can I send selected photos to devices?
    Thanks

    2-factor authentication sounds good but what if in the cloud sends your photos to someone else's account?
    yeah I know sounds like someone with no idea about how these things work, well please read on.
    i posted this last night on tis same forum, and have not received any help on it so far:
    subject: Major security issue! I can see 100's of other peoples photos, Help!
    Oct 1, 2014 4:39 AM
    Using iPad Mini / iPhone 4S
    I have just recently enabled the iCloud Photo Library (Beta). I also use MS Onedrive and i have it setup to automatically backup all my photos and      videos from both my iOS devices.
    Today i opened Onedrive for no particular reason and clicked on the Photos tab, this shows the progress of photos being backed up, only this time i      scrolled down to find that there was hundreds of photos from different families mixed in with mine dating back to 2002! Naturally the first thing i am      thinking is who is looking at my photos/files. What is going on!!!!
    Let me just assure anyone reading this, that the owner of these photographs would not appreciate anyone else having them, these are Kindergarten,      public school and family photos of complete strangers. and all my photos are mixed in between them.
    Is anyone else having this issue
    iPad mini Wi-Fi + Cellular (MM), iOS 8, iOS 8.0.2

  • How to stop workitem complete or how to keep work item in inbox based on conditions even if it completed

    Hi,
    my requirement is to call webdyn pro screen from workflow..
    i am calling webdynpro screen by using FM :CALL_BROWSER from workflow.
    when webdyn pro screen is called user will enter some values . if user closed webdyn pro screen with out entering any values we need show this workitem in his inbox. so that user can again open it and enter values in the webdyn pro screen.
    Please help how to stop work item complete based on conditions.
    Thanks,
    phani

    Hi,
    As per my understanding, this is not a proper approach toy call web dynpro using FM CALL_BROWSER. is the web dynpro screen being called when user clicks on the work item from portal UWL OR from SAP SBWP ?
    if you are calling web dynpro screen from portal UWL when user clicks on work item link, better you achieve it using SWFVISU tcode. in SWFVISU tcode you can maintain which web dynpro. application to call when particualr work item task come in user's inbox. in your web dynpro code, then you can write your buisiness logic when user clicks for example SUBMIT/SAVE button. on action submit/save button you can use FM SAP_WAPI_WORKITEM_COMPLETE to complete the worktiem once the user clicks on final submit/save button. in this way the workitem will get removed from user inbox only upon clicking on submit/save button.
    You can refer below link for web dynpro for workitem:
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/70648e99-4cc1-2c10-879d-9c61003c69d6?QuickLink=index&…

Maybe you are looking for

  • Issues with flash and other adobe products.

    Ok, so i've been using flash player for quite a number of years now aswell as other products like acrobat reader when i used windows, over the years flash player has developed into a totally inneffecient and almost unusable product. on top of the sec

  • How do I disable the new feature that disables outdated plugins unless they are clicked?

    I'm running Adobe Acrobat 8. I'm happy with it. Firefox has a new feature that automatically disables the PDF plugin unless it's clicked. It's called the "Click to Play" feature. Even when disabled, it's not really disabled: it activates itself for "

  • Oracle 11gR2 RAC on Linux - testing/practice/lab purpose

    Hi Gurus, Need your assistance & help here, I've 3 servers, equipped with almost everything, for this testing/sufficient enough; cpu, memory & hard disk. I'm looking for some guidance/assistance or link, doc or anything, which I should follow to buil

  • Wuc-19 when moving between multiple forms applications

    Hi, We have 3 forms based systems running from 2 seperate instances so our app server farm consists of.. DEVELOPMENT SUPPORT INTERNAL and of course the standard INFASTRUCTURE we have webutil installed on all these systems. we recently implemented som

  • Start up screen bringing up a random email

    Like many other people, to install iOS 8, I had to free up some space. To do this I decided to back up my iPhone, erase everything on it, install iOS 8 and then restore my phone. Upon restoring, it asked me to sign into my account, which was successf