aspose file tools*
The moose likes Associate Certification (OCAJP 7) and the fly likes Coffee and Diamonds on Valentine Day Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7)
Bookmark "Coffee and Diamonds on Valentine Day" Watch "Coffee and Diamonds on Valentine Day" New topic
Author

Coffee and Diamonds on Valentine Day

Mala Gupta
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 250
    
    9
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


Author of Manning's OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

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


When The Going Gets Tougher,The Tougher gets Going
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4363
    
    8

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

Joined: Jul 01, 2008
Posts: 507

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
Bartender

Joined: Jul 19, 2004
Posts: 5201
    
  12

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


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

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
Bartender

Joined: Jul 19, 2004
Posts: 5201
    
  12

It still has an unneeded return statement. So no full marks yet
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

I have edited my code.Please check @Roel.

Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5201
    
  12

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Coffee and Diamonds on Valentine Day