This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Questions from Mock exam

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,



Source : javablackbelf.com
1)
If a Runtime Exception is thrown in the finalize method



a)The running application crashes.
b)The exception is simply ignored and the object is garbage collected.
c)The exception is simply ignored, but the object is not garbage collected.
d)The Exception causes the JVM to crash.


My Answer is : d). JVM wont collect the object when the runtime exception occurs. Then it garbage collects it next time wihtout calling the finalize() method.

correct answer given is : b)


2)
When does the JVM exit?

a)After the main method returns.
b)After all the non-daemon threads created by the application complete.
c)After all the daemon threads created by the application complete
d)When a thread executes System.exit();
e)When an uncaught exception is thrown in a non-demon thread.
f)When an uncaught exception is thrown in a demon thread.



My Answer is : b) , d), e)

Correct answers given is b), d)


Can any one explain me these as per answers?

rami
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ram,

When does the JVM exit?
e)When an uncaught exception is thrown in a non-demon thread.



This would not happen since its not that if an exception occurs in one of the runnning threads, it shouuld occur in other threads too... So jvm can safely run the other threads...

for eg:


output:

Exception in thread "Thread-0" java.lang.ArithmeticException: / by zero
at TryingThreads.run(TryingThreads.java:7)
at java.lang.Thread.run(Thread.java:595)
Thread-1 completed
Thread-2 completed



Regards,
Vishwa
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As to the first question, nothing should cause the JVM to crash.

From the javadocs of Object.finalize: Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored. In particular, it doesn't prevent GC'ing it.
[ June 13, 2008: Message edited by: Ulf Dittmer ]
 
Ram Reddy
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks vishwanth murthi.
That is really nice example
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic