• 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
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Doubts on practice exam: serialization, coupling

 
Ranch Hand
Posts: 50
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys. I have a couple of questions from an official practice exam I did tonight. Here they are:


1) We all know that static variables are not serialized. When serializing and deserializing an object in the same execution, the static variables don't change their values, isn't it?

The answer implied that they were reset to their initial declaration value, and I'm starting to think it was an errata.



2) Another answer claimed that a composition scheme where a Class A holds a reference to an instance of another Class B, and at the same time class B has an instance of class A, is tight coupling. Reading from chapter 2 in K&B's book, it is said:

Tight coupling is the undesirable state of having classes that break the rules of loose coupling.



So if we read those rules, they say:

Loose coupling is the desirable state of having classes that are well encapsulated, minimize references to each other, and limit the breadth of API usage.



In the question, classes A and B were well encapsulated (private references, only setters with package-default access modifier), and no method calls over the instances were made (and of course no inner variables were accesed from outside the class). Why are then considered tigthly coupled? Should I consider tight coupling every composition (has-a relationship) where references are not interfaces? Or even with interfaces it is considered tight coupling? Do you have a rule of thumb for this kind of question?

Thanks.
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi , let me try to explain it , but need to mention, i am a java rookie , hahaha

1) do you have the question? please post it here, so we can help you figure out the answer. but as you said, serialization has no effect on static variable. but it is possible the constructor is changing the value of static variables. this is my guess so please post the question here.

2)



the answer is follow:



normally i ask myself, if i modify object A, does it affect the object B? is the answer is yes, then it is tight coupling.

actually the definition of high or low coupling is vague , so for the exam, you can spot the keyword in order to score the question. (like the sample above.)

 
John Schubert
Ranch Hand
Posts: 50
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here`s question 1:

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




A) 0 0 0
B) 0 7 0
C) 0 7 7
D) 7 0 0
E) 7 7 0
F) 7 7 7
Solution: Option B is correct. Because static variables belong to the class and not to instances of a class, they are not serialized.


I think option E is correct, because on line 6 x1 is assigned the value 7, and it remains the same during the entire execution.
 
jamil lusa
Ranch Hand
Posts: 59
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yo man, this question has been asked for several time. (i think i have seen similar question for several time XD)

i suppose you found the question from here:
http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=303&p_certName=SQ1Z0-851&p_org_id=15943&lang=US
please check the question objectives 3.3 agian. if you don't see anything, choose the location where you are.
 
John Schubert
Ranch Hand
Posts: 50
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jamil lusa wrote:yo man, this question has been asked for several time. (i think i have seen similar question for several time XD)

i suppose you found the question from here:
http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=303&p_certName=SQ1Z0-851&p_org_id=15943&lang=US
please check the question objectives 3.3 agian. if you don't see anything, choose the location where you are.



Thanks!
Actually I didn't found the question there. Anyway, I hope the errata was only on my question solutions and it is never going to happen in the real exam XD.
 
Friends help you move. Good friends help you move bodies. This tiny ad will help:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic