Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Coffee and Diamonds on Valentine Day

 
Mala Gupta
Author
Ranch Hand
Posts: 296
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that the topic of this thread is funny, but that will add to what I'm sharing in this thread.

A quick comic converation (used in this book) can help you to remember a simple, yet important concept for this exam. For example the image that follows will help you to remember - A finally block (try-catch-finally) will execute even if the code in the try or any of the catch blocks defines a return statement.



You can compare the try block to the purchase of diamonds and the finally block to the coffee treat. The girl gets the coffee treat regardless of whether the boy successfully purchases the diamonds or not.

Can you cook up and share your own? :-)

With respect,
Mala
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mala,
A nice comic representation !!! i appreciate your creativity.Can you check whether my below interpretation is right or wrong in terms of "Java Code",Can you please correct if im wrong.




Can you please correct the code if im wrong.

Regards,
Deepak Lal
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The finally block is run regardless of whether the main block executes successfully, or whether an exception is thrown. So if there are no exceptions then you'd be buying her two coffees. Which may or may not be a problem, depending on how sensitive she is to caffeine!

You don't need either of the return statements either.
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mathew,Thanks for the correction,can you check my code now


But what if there is no exception for diamond,she would be getting that as well !!!Hence a girls best friend are diamonds :-))


Regards,
Deepak Lal
 
Roel De Nijs
Sheriff
Posts: 10223
129
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak,

Is it possible to change the code snippet to its orginal form? And just make a follow-up post with your changes. So it's easier for other ranchers to follow this thread better (and maybe also learn something). Because now when I look at it, I have no idea why Matthew said that you would buy her 2 coffees when there are no exceptions Thanks!

Like Matthew already indicated: both return statements are not needed.

Kind regards,
Roel

[edit] changed code snippet to original state
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roel for the immediate updated reply so the final code is as below.(removed unwanted return from try and catch blocks)




Hope I'm finally correct now.Thanks all for your support in this Thread.



Regards,
Deepak Lal
 
Roel De Nijs
Sheriff
Posts: 10223
129
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It still has an unneeded return statement. So no full marks yet
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have edited my code.Please check @Roel.

 
Roel De Nijs
Sheriff
Posts: 10223
129
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic