Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

OCPJP sample question wrong on Oracles website

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am sitting the OCPJP exam this week and I just came across this question in Oracle's list of sample questions for the exam.



If, on line 7, t is successfully serialized and then deserialized, what is the result?

The answer they give is "0 7 0" as correct, stating correctly that static or transient variables are not serialized.

However x1 should still be 7, the same as it is set two lines above as it is static.

So the answer should be 7 7 0.

This does not inspire me with confidence for the exam

The question can be found on the link below, labeled objective 3.3

// You might need to select your region
http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=303&p_certName=SQ1Z0-851
 
Ranch Hand
Posts: 72
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gordon Keenan wrote:Hi,
I am sitting the OCPJP exam this week and I just came across this question in Oracle's list of sample questions for the exam.



If, on line 7, t is successfully serialized and then deserialized, what is the result?

The answer they give is "0 7 0" as correct, stating correctly that static or transient variables are not serialized.

However x1 should still be 7, the same as it is set two lines above as it is static.

So the answer should be 7 7 0.

This does not inspire me with confidence for the exam

The question can be found on the link below, labeled objective 3.3

// You might need to select your region
http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=303&p_certName=SQ1Z0-851



If this is indeed the answer they give you - it is wrong. It should be 7 7 0 as you pointed out. I should not worry about it too much. Just follow the principles and you will be fine.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Has Serialization not been removed?
 
Boris Mechkov
Ranch Hand
Posts: 72
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ai dan wrote:Has Serialization not been removed?


It has, so i was surprised when you mentioned this. But, serialization is not that hard to grasp so i would learn it anyway.
Good luck!
 
Gordon Keenan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ai dan wrote:Has Serialization not been removed?



Why would serialization be one of the sample questions if it has been removed, is it another oracle mistake?

Most of the material I have read said has said the topics are identical for the SCJP and OCPJP.
 
Gordon Keenan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just as a follow up I found the same question on the mock exam from Pearson Vue and they also have the answer wrong.

I just hope it doesn't come up as I will not be sure what to select
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found this in one of java wesites.As per the above explanation, static variable also would not have got the original value after serialization.
I didnot try executing though!
-----------------------------
What are Transient and Volatile Modifiers

A transient variable is a variable that may not be serialized i.e. the value of the variable can’t be written to the stream in a Serializable class. If you don't want some field to be serialized, you can mark that field transient or static. In such a case when the class is retrieved from the ObjectStream the value of the variable is null.

Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are wrong, Oracle's answer is correct. The Answer will be 070, because, serialization will not consider static (x1) and transient(x2). They generally consider that the program will be deserialized at a later time or that it will be deserialized on client. In this paticular case, you are setting static int to 7, and if-and-only-if you serialize and deserialize immediately then you will get x1 to be 7

When you deserialize Traveler, you will do something like this:


 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Anang about 070. I don't see how the static x1 can retain its value of 7 through the process of serialization and then deserializtion.

Regards,
Dan
 
Ranch Hand
Posts: 66
Android IntelliJ IDE Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I purchased the practice exams available directly from Oracle. I, too, found a couple of questions where I disagreed with their 'correct' answer. As I was studying, my general procedure was to take the code in the questions I missed and actually plug it in to Eclipse and see who was right.

A different concern with the practice tests from Oracle was that I saw duplicate questions 5 or 6 times in a question that had only 60 questions.

Best of luck on the exam!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic