• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

small mistake in ExamLab

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and im just as stunned as you are... wonder whats happening... but im pretty sure that my exam certificate says that the cut off mark is 66% or so....
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how long is taht ago?

i'm making this examn from the examlab and i do not understand a question:

It's a question about serialization,

A class Forest has a Tree but it is declared static...
The Tree class does not implements Serializable.
Now they try to serialize a forest object, so i think this must succeed without exception that class Tree needs to implement Serializable?

Why? Because static vars aren't serialized right...

any help?
 
Suranga Nath Kasthurirathne
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that was on the first of this month
 
Suranga Nath Kasthurirathne
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static objects wont get serialized.. but that wont give an error.. only when you try to access the static object do you get a null pointer excaption..

but if it was not static and yet did not impliment serilizable then an exception is thrown because it sees that tree is not serializable...

hope that this answer is correct ...
 
Tommi Vd
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you say what i mean, but in the question of the exam it gives an exception because the class Tree is not serializable...
But the instnace of tree is declared static in the class from witch an instance gets serialized...
So actually there shouldn't be an error...?


you understand what i mean?





Here the answer is exception thrown because class Tree isn't serializable. But the instance of Three in Forest is static...
 
Tommi Vd
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone?
 
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You pass that static reference to writeObject method so JVM is going to serialize it - but the exception is thrown.

But Serialization won't be one exam. Bert wrote that.
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thomas Van Driessche wrote:Anyone?



Please read this. You should be patient about answer to your questions ...
 
Tommi Vd
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops sorry

not a reference of tree is passed to writeobject, a reference of f.
And since the instance var tree from f is static, there shouldn't even be a try to serialise that...
So there can not be thrown a runtime exception though?
 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well....passing the tree reference is ok. But letz see the JVM looks at the class and sees the class Forest is serializable and what's this this class has a relationship with the Tree class i.e Tree is in the Object graph of Forest. So following the all or nothing rule the JVM fails at runtime throwing the NOSerializtionError : Tree.
 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thomas Van Driessche wrote:oops sorry



You broke another rule No Need To Say Sorry. But don't say sorry for breaking the rule or you'll broke that rule again

not a reference of tree is passed to writeobject, a reference of f.
And since the instance var tree from f is static, there shouldn't even be a try to serialise that...
So there can not be thrown a runtime exception though?



Your Forest class itself is not serializable. Its not about the Tree class. Your Forest class needs to be serializable for you to be able to serialize its objects...
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually he copied the question wrongly from examlab. Well here yes the FOrest is not serializable. Even if it implemented Serializable then also no instance of forest will be serializable. This question was discussed here Coderanch
 
Tommi Vd
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static variables are implicitly transient - that's true, but it will not apply here, because we are serializing the object of the tree variable directly.

i do not really get this...
is it because the reference to the object is static? but the object itself isn't?
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AGAIN: Serialization will NOT be on exam! And read my post above. Thanks!
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This is 44th question of Examlab. Well I think the explanation is a little bit off. See when mt2.start() is executed it will not run. Main will continue to run and will append sb1 and then it sleeps. So synchronization or not this code is fine. In the explanation it was said that the lock sb1 was held by a thread but due to non synchronized methods it can change it.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The whole question is good, but tricky.


The only thing that will be printed is: BuilderPassed,

ExamLab's thread questions are the hardest ones
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the answer right i understand the problem. I read the explanation and i thought the explanation was little off coz the m2.start() doesn't run untill the thread sleeps again. So what i was telling is that m2 won't run so it won't acquire the lock for sb1 that's all.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you know that mt2 won't run? You can not predict it. Thread Scheduler can put MainThread into Runnable and let mt1 to go. The fact is Thread.sleep(...) helps with thread switching but without it the switching can perform.
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the other way round is also can be debated on....but here those things don't matter hehe.
 
reply
    Bookmark Topic Watch Topic
  • New Topic