File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Serialization" Watch "Serialization" New topic
Author

Serialization

Mohit Daga
Greenhorn

Joined: Apr 14, 2011
Posts: 15
Hi all..
Am studying serialization from the Sierra-Bates SCJP book..Here it says that when we try to serialize/deserialize a transient class variable by writing our own writeObject/readObject method
the return type of the readObject method is void.It goes like-
private void readObject(ObjectInputSteam is)
But isnt the method supposed to return an Object??
Else how do we get the deserialized object?
Thanks in advance..


OCPJP 6!
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

1. Serialization is not on the exam, so you can relax.
2. Also the readObject method is supposed to set properties of the class in which its implemented i.e. the this reference...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Torsten Oppermann
Ranch Hand

Joined: Dec 22, 2010
Posts: 62

Serialization is not in the exam ?? can someone confirm this ? i just practiced the serialization part today :/


OCPJP 6 - 93%
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Torsten Oppermann wrote:Serialization is not in the exam ?? can someone confirm this ? i just practiced the serialization part today :/


Ikpefua wrote:

Hello Torsten, It is true that Serialization has been removed from the exams, here is the link:

http://www.coderanch.com/t/527879/java-programmer-SCJP/certification/Deal-Changing-Objectives

Be informed that NOT all exam centers have been updated, I advise you to go ahead and study it.


OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Ikpefua Jacob-Obinyan wrote:Be informed that NOT all exam centers have been updated, I advise you to go ahead and study it.

Serialization was removed from the exam more than a year ago. Its highly unlikely that you'll face any serialization questions on the exam, but again as Ikpefua said, there is not hard in gaining some knowledge. Be sure to focus more on other topics which are part of the exam...
Mala Gupta
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 251
    
    9
Ikpefua Jacob-Obinyan wrote:
Be informed that NOT all exam centers have been updated, I advise you to go ahead and study it.


I believe that the exam is downloaded from the Oracle's website, just before you are ready to start with your exam. If this is the case, then how is it possible that some centres may not have been updated?? Is it possible that some centres download and store the exam and reuse it over a period of time??

Mala


Author of Manning's OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Mala Gupta wrote:
Ikpefua Jacob-Obinyan wrote:
Be informed that NOT all exam centers have been updated, I advise you to go ahead and study it.


I believe that the exam is downloaded from the Oracle's website, just before you are ready to start with your exam. If this is the case

Mala

Ikpefua wrote:

@Mala I am afraid I am NOT in any position to answer questions based on your 'believe' and your 'if'. Please click on the following link and READ carefully.

http://www.coderanch.com/t/527879/java-programmer-SCJP/certification/Deal-Changing-Objectives

NOTE: That I am NOT trying to be arrogant, I am simply trying to make you understand the difference between 'what-we-believe' AND 'reality'.
Mala Gupta
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 251
    
    9
Ikpefua Jacob-Obinyan wrote:
@Mala I am afraid I am NOT in any position to answer questions based on your 'believe' and your 'if'. Please click on the following link and READ carefully.


I would refrain from posting a statement, if I am not sure about it.

Anyway, Thanks for the link.

Mala
Mohit Daga
Greenhorn

Joined: Apr 14, 2011
Posts: 15
If they do give the old format in certain places,then they might also stick to the old 72 question format.right?i am due to give the exam on the 23rd.
Mala Gupta
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 251
    
    9
Mohit,

I would strongly recommend you to call up the center where you have scheduled your exam and talk about your concerns with the best person. I would also recommend that you ask them how can you be sure that you get the questions as per the latest exam objectives, especially when people on forums like this are claiming to have written an exam on an earlier version.

Additionally, it is always helpful if you are well informed about the exam details. Note down the total exam questions and passing score from Oracle's website and talk to them (your exam center) about these numbers.

Post your experience here. It will help others.

cheers
Mala
Mohit Daga
Greenhorn

Joined: Apr 14, 2011
Posts: 15
Thanks a lot,Mala.Will surely post about the exam.I just hope I am able to pass!
Mala Gupta
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 251
    
    9
Mohit,

Please share your experience of querying the exam center about how do they ensure that candidates get to attempt the SCJP/ OCPJP exam on the latest exam version.

I wish you Good Luck.

cheers
Mala
Mala Gupta
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 251
    
    9
Ikpefua,

No need for guess work, anymore. This query (questions on exam objectives that have been removed from the latest SCJP/ OCPJP) exam has been answered by Gary Fluitt, Senior Manager, Oracle Certification Program, Oracle, in the following thread:

http://www.coderanch.com/t/527879/java-programmer-SCJP/certification/Deal-Changing-Objectives

cheers
Mala
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Mala,
Thanks for passing on this information. As you said there's NO need for guess work anymore!.
In general I will advise that if you have time to study serialization, wait(), notify() etc go ahead, there's NO harm in adquiring more knowledge, in fact this helps you better equiped for your first job!.

Cheers!.
Ikpefua.
Mohit Daga
Greenhorn

Joined: Apr 14, 2011
Posts: 15
Mala,
The exam centre people I called were not very helpful regarding the matter.They tell me that they have recently received a mail from Oracle which says that a new format for the exam is to be implemented in "short time".This,new format he says has not been implemented before.Any idea about this?According to the person it might just be implemented anytime since the date was not specifically mentioned.Also,the person tells me that the exam is downloaded from Oracle at the time one is giving the exam.And not stored in the centre as some were saying.Puts me in a pickle, this situation!
Hope this helped.
Mohit
Mala Gupta
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 251
    
    9
Ikpefua Jacob-Obinyan wrote:Mala,
In general I will advise that if you have time to study serialization, wait(), notify() etc go ahead, there's NO harm in adquiring more knowledge, in fact this helps you better equiped for your first job!.

Cheers!.
Ikpefua.


Thanks, Ikpefua. I have already earned my SCJP certification and used these with real life projects! :-)

cheers
Mala
Mala Gupta
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 251
    
    9
Mohit Daga wrote:Mala,
The exam centre people I called were not very helpful regarding the matter.They tell me that they have recently received a mail from Oracle which says that a new format for the exam is to be implemented in "short time".This,new format he says has not been implemented before.Any idea about this?According to the person it might just be implemented anytime since the date was not specifically mentioned.Also,the person tells me that the exam is downloaded from Oracle at the time one is giving the exam.And not stored in the centre as some were saying.Puts me in a pickle, this situation!
Hope this helped.
Mohit


Mohit,

I am afraid I am not aware of/ don't have any info on the change in the exam format.

I would recommend that you inquire with the exam center regarding the changes in the format of the exam - change in the number of questions/ duration/ passing score/ any other? If they don't know abt the change/ aren't willing to share the details, you can contact Oracle directly yourself. Try the following link:

http://www.oracle.com/us/support/contact-068555.html#asia

You can also email folks at Oracle/ post a question at a relevant thread at blogs.oracle.com. The folks there are pretty good and you should receive a reply very soon.

cheers
Mala
Mohit Daga
Greenhorn

Joined: Apr 14, 2011
Posts: 15
Thank you,Mala for being so awfully helpful!yet to confirm with the Oracle guys,how its going to be.
Achilleas Achix
Ranch Hand

Joined: Apr 18, 2011
Posts: 123

I know that Serialization is not in the exam, but i got puzzled by question 12 in the 6th chapter.
It goes like:



I think, since the actual serialization code is not included, and also since someone could take complete control of the serialization/deserialization process by implementing writeObject and avoiding the call of defaultWriteObject, i think that C can also be correct. If the question provided actual serialization code , showing e.g. no implementation of writeObject, then correctly, C would be indeed wrong. ( ).
As is, however, i think we should give C a chance.


OCPJP 6.0
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Hello Achilleas,
please READ CAREFULLY the reason why option C CANNOT and should NOT be given a chance the answer explains it perfectly, REMEMBER that it is required that classes whose objects you intend to serialize MUST implement the Serializable interface -to the best of my knowledge- instance variables marked with the transient modifier are the ONLY elements that can be manually written using the defaultWriteObject() method.

I hope this helps.
Achilleas Achix
Ranch Hand

Joined: Apr 18, 2011
Posts: 123

Ikpefua Jacob-Obinyan wrote:Hello Achilleas,
please READ CAREFULLY the reason why option C CANNOT and should NOT be given a chance the answer explains it perfectly, REMEMBER that it is required that classes whose objects you intend to serialize MUST implement the Serializable interface -to the best of my knowledge- instance variables marked with the transient modifier are the ONLY elements that can be manually written using the defaultWriteObject() method.

I hope this helps.


Have you READ CAREFULLY what i wrote?
In addition you got it all wrong in the sentence
instance variables marked with the transient modifier are the ONLY elements that can be manually written using the defaultWriteObject() method

1st, it is not the defaultWriteObject() method but the writeObject() method, and 2nd, there is no rule that writeObject() must always call defaultWriteObject() and also must manually deal with transient variables. Transient is just a marker for ObjectOutpuStream to ignore one (or more) variables, in order to avoid NotSerializableException.
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Ikpefua wrote:

Achilleas,
the question says: "instances of which classes can be serialized???"

We know the FIRST rule, that it is OBLIGATORY that classes whose instances can be serialized MUST implement the Serializable interface (I hope you are aware that this rule is NON negotiable??....)

Take a CLOSE look at the code:


In other to understand perfectly the above explanation you have to recognise first the difference between Is-A and Has-A, AND how they affect serialization.
Taking into consideration the above VOILATION, why should option C be correct???

Thanks in advance for your response.
Achilleas Achix
Ranch Hand

Joined: Apr 18, 2011
Posts: 123

Take a look at this code:

Collar.java


Animal.java


Dog.java


Now please note, Collar collar is *NOT* Serializeable, Dog d HAS-A Collar collar, yet, (surprise!) Dog d, gets perfectly serialized/deserialized, *WITH* Collar included in its initial form.
Of course along the non serializable HAS-A Collar, also the case with non-serializable ISA Animal is also demonstrated as well.

What would the output be if Animal had only the one-arg constructor? Can you figure this out?
What would happen if I attempted to insert something like : stream.defaultWriteObject() after line 45 and stream.defaultReadObject() after line 39 ?
(Let me answer the second question : Putting the above two lines, is the *ONLY* way that C can be wrong).
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Achilleas,
I am NOT a java guru, I am NOT even certified, I was only trying to make you realize why option C is wrong (according to the logical explanations provided by K & B), if you do NOT agree its okay, I am NOT in a position to argue that with you, you can forward your arguments to the authors of K & B book to explain why C should be added, as for me I AGREE with the K & B options A & B as valid answers untill otherwise proven.

We hope they -K & B- Authors are seeing reading this thread to provide useful explanations. thank you for your understanding.

Achilleas Achix
Ranch Hand

Joined: Apr 18, 2011
Posts: 123

Ikpefua Jacob-Obinyan wrote:as for me I AGREE with the K & B options A & B as valid answers untill otherwise proven.

The above code is the "otherwise" proof, you are looking for.
In addition, you don't have to be a java guru to see what is going on, compile and run this code on your own computer and see what you get.

There is a section about errata in the K&B book, right? I guess you would hold the same stance against those as well, until "otherwise" proven?
Jesus, this is needlessly turning to a rant, because of a single person who was too lazy to do his own homework.
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Achilleas,
thank you very much for your efforts, at this point I want to appeal to you to RESPECT my PERSONAL decision, I have PERSONALLY decided to stay with the K & B option. Please transfer your 'otherwise proof' and complains to the authors of the K & B book. I have a LOT of other studies (CONCERNING THE EXAMS) to spend my limited time on. I hope you understand.
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Achilleas Achix wrote:

Jesus, this is needlessly turning to a rant, because of a single person who was too lazy to do his own homework.

Ikpefua wrote:

Achilleas can you explain the above??? I dont understand what you mean. I NEED an explanation as soon as possible, or I will have to make complains to the organisers of javaranch about the use of UNFRIENDLY language.
Achilleas Achix
Ranch Hand

Joined: Apr 18, 2011
Posts: 123

Ikpefua Jacob-Obinyan wrote:
Achilleas Achix wrote:

Jesus, this is needlessly turning to a rant, because of a single person who was too lazy to do his own homework.

Ikpefua wrote:

Achilleas can you explain the above??? I dont understand what you mean. I NEED an explanation as soon as possible, or I will have to make complains to the organisers of javaranch about the use of UNFRIENDLY language.


I am the one who should report you for spreading confusion about things you don't even seem to understand.
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Achilleas, I have invited a moderator of javaranch to intervene and resolve whatever problems there are.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hey Achilleas and Ikpefua,

Let's all take a deep breath and chill out a little bit. Remember that people from all over the world are asking and answering questions on this forum. Because of that it's easy to take a simple statement incorrectly, so your first rule should be "patience".

As for this question, Achilleas the general rule for the Java exams is that the code a question shows you is the code you need to see to answer the question. In this case, there can't be other code for class Wheels or for class Dodge. Where would that extra code be located?

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Achilleas Achix
Ranch Hand

Joined: Apr 18, 2011
Posts: 123

Hello Bert, thanks for the fine book, it is a fun to read!
I hope you and Kathy are well, healthy and kicking!

I see your point, regarding the question. Maybe there is a difference between "can", "could" and "can instantly be, right out of the box".
I get your point, thanks, so one should form an idea of an average degree of difficulty of the questions, and apply it to all questions.
Questions are not supposed to be neither ultra tricky-hard, nor very easy to answer.
There is a certain spirit, which should be taken into consideration.

The problem with this question, is that the code seems too empty and abstract, that the reader could easily assume that there is more to it.
The notion i would like to stress, is that by taking complete control of serialization, one could serialize even non-transient non-serializable instance
variables.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hi Achilleas,

I think you still have some points of confusion here. Try to answer these questions:

- What kinds of things get serialized?
- In the question you listed, is all the code valid?
- Is an 'empty' class still a valid class?

Remember, on the real exam there isn't a lot of room for many lines of code, so it's most typical that you'll see a lot of code scrunched into a few number of lines.

hth,

Bert
Achilleas Achix
Ranch Hand

Joined: Apr 18, 2011
Posts: 123

Thanks Bert.

However the classes are NOT public, and since they are our/mine/yours classes, i don't see any reason why having the examined person *imagine* code for the calls to ser/deser, should not leave open the possibility to imagine code to implement writeObject/readObject inside the Dodge class. You will tell me, but the Dodge class does not have such code!!! Alright i'll tell you!! the question does not have serialization code either! Just try to understand my POV.
If OTOH the classes were public, officially released for the world to use, then Dodge would be doomed to not be out of the box serializable.
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Ikpefua wrote:


OFFICIAL MOCK EXAMS TEST QUESTION 25 THE SOURCE IS OUKC (ORACLE UNIVERSITY KNOWLEDGE CENTER).

Which two about using the java.io.Serializable class are true? (Choose two.)

A. If Dog extends Animal, then Animal must implement java.io.Serializable in order to serialize an instance of Dog.

B. If Dog has-a Collar, then Collar must implement java.io.Serializable in order to serialize an instance of Dog.

C. If Dog extends Animal and Animal implements java.io.Serializable but Dog does NOT implement java.io.Serializable, you can serialize an instance of Dog.

D. When an instance of a subclass is deserialized, none of the constructors in it's constructor chain will ever be invoked.

E. If you mark a class's instance variable volatile, and then serialize an instance of that class, the state of the volatile variable will be lost during serialization.

_________________________________________________________________________________________________________________________________

Options B and C are correct. A class's superclasses don't have to implement Serializable in order to be serialized, and if a superclass doesn't implement Serializable then it's constructor will run during deserialization. A transient variable's state is lost during serialization, but a volatile variable's state is not lost.
_________________________________________________________________________________________________________________________________

Hello Bert,
this is official from Oracle, the owers of Java, I have DOCUMENTAL proof of legally adquiring this mock exam. Is this not even more 'abstract' -according to Achilleas- than the question in your book?.
Lets stop bothering ourselves about UNECESSARY arguments, take a deep breath and move forward, I have made a choice AND that choice is K & B AND Oracle. I DONT CARE about any other logics behind this issue.

Thank you very much.

Ikpefua



Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hi Achilleas,

You said,

imagine code to implement writeObject/readObject inside the Dodge class


For the purpose of the exam, you must learn how to read the questions very, very carefully. An important part of studying for this certification is learning how to read the questions precisely. Personally, I think that this is a very justifiable proposition. In the real world, as a software developer, a BIG part of your job will be precise communication. For instance, you might have to work from a specification that someone else created. In that case, you don't get to "imagine" possibilities, you need to implement what's been specified.

So, on the exam, you're not being asked "what could I possibly do to enhance this code". You ARE being asked to look at the code - AS IT STANDS - and make some determination. This is the pattern for almost ALL of the real exam questions you'll encounter.

Does that help?

Bert


Mohit Daga
Greenhorn

Joined: Apr 14, 2011
Posts: 15
Hi.
I hope i am not getting into the middle of something,but I still do not understand my problem with which I started the thread.Hope the question is sensible enough since "There are no dumb questions."B-).Thank you.
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Mohit Daga wrote:Hi all..
Am studying serialization from the Sierra-Bates SCJP book..Here it says that when we try to serialize/deserialize a transient class variable by writing our own writeObject/readObject method
the return type of the readObject method is void.It goes like-
private void readObject(ObjectInputSteam is)
But isnt the method supposed to return an Object??
Else how do we get the deserialized object?

Hello Mohit, I consulted the official java documentation API http://download.oracle.com/javase/6/docs/api/, and it gives a clue on how the readObject method behaves here is a caption of what they say:

Classes that require special handling during the serialization and deserialization process must implement special methods with these exact signatures:

private void writeObject(java.io.ObjectOutputStream out)
throws IOException

private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException;

The writeObject method is responsible for writing the state of the object for its particular class so that the corresponding readObject method can restore it. The default mechanism for saving the Object's fields can be invoked by calling out.defaultWriteObject. The method does not need to concern itself with the state belonging to its superclasses or subclasses. State is saved by writing the individual fields to the ObjectOutputStream using the writeObject method or by using the methods for primitive data types supported by DataOutput.

The readObject method is responsible for reading from the stream and restoring the classes fields. It may call in.defaultReadObject to invoke the default mechanism for restoring the object's non-static and non-transient fields. The defaultReadObject method uses information in the stream to assign the fields of the object saved in the stream with the correspondingly named fields in the current object. This handles the case when the class has evolved to add new fields. The method does not need to concern itself with the state belonging to its superclasses or subclasses. State is saved by writing the individual fields to the ObjectOutputStream using the writeObject method or by using the methods for primitive data types supported by DataOutput.

Take note of the very first sentence: The readObject method is responsible for reading from the stream and restoring the classes fields. I think this is the reason why it does NOT return an Object.
_________________________________________________________________________________________________________________________________

N.B. If you click on the link http://download.oracle.com/javase/6/docs/api/, under packages click on java.io, under Interface Summary click on Serializable and you will see the above explanation.

I hope this helps.
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432

Uff..Very Very Long Discussion ..but Yeah could be Useful!


SCJP 6 | FB : Java Certifications-Help. | India Against Corruption
Mohit Daga
Greenhorn

Joined: Apr 14, 2011
Posts: 15
Ikpefua,
Thank you.I had to read through the thing a couple of times to get the hang of it!
Chandella Montero
Ranch Hand

Joined: Feb 18, 2011
Posts: 89
Hey Achilleas, I ended up here because I had exactly the same line of thought as you, and I wasn't very happy with the explanation in the book for why C wasn't correct. Class Dodge, as I see it, can be serialized because there is a way to do it.

Never mind, I think this discussion has been pretty much exhausted anyway. What I was wondering, rather, is whether Serialization had indeed been removed from the objectives. Is it confirmed? Can I stop studying for it and concentrate on the other chapters?


OCA, OCP Java 6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serialization