Java - Interview Questions and Answers for 'Finally' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Finally' - 13 question(s) found - Order By Newest

Very frequently asked. Favorite question in Walk in Drive of many Indian service companies. Frequently asked in HCL Technologies.
  Q1. What is the difference between final, finally and finalize() ?Core Java
Admin
info@buggybread.com
Ans. final - constant variable, objects cannot be de-referenced, restricting method overriding, restricting class sub classing.

finally - handles exception. The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block. Use the finally block to close files or to release other system resources like database connections, statements etc.

finalize() - method helps in garbage collection. A method that is invoked before an object is discarded by the garbage collector, allowing it to clean up its state.

  Sample Code for final

  Sample Code for finally

  Sample Code for finalize

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   final   finally   finalize     Thomson Reuters  WITS  Antra  Jive  MorningStar  VanGuard   Alcatel Lucent  Morningstar  A9.com  EPAM  Nuance  SirsiDynix  NCR  VanGuard  Proofpoint Interview  Disney  Orbitz Worldwide  GFI Informatique  Canon  WITS  Simba Technologies  Marlabs  American Well  Global Relay  L&T Infotech  HCL Technologies  Tata Consultancy (TCS)  Wipro  Infosys  Accenture  Jive  Salesforce  Deegit  NTT DATA  Proofpoint  Morningstar  Bank Of America  Manhattan Associates  Optum  NorthPoint  Nok Nok Labs  Simba Technologies   Rhino Africa  Solutionreach  V Soft Consulting  EBay  Cognizant (CTS)  IBM  ExactTargetKewill  CV Holdings  Symphony  Cubic Web solutions  Star International  FatWire  Mindteck      basic        frequent

Try 4 Question(s) Test


 Q2. How can we make sure that a code segment gets executed even in case of uncatched exceptions ?
Anonymous
Ans. By putting it within finally.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   exceptions   finally   uncatched exceptions      basic        frequent


 Q3. Is it necessary that each try block to be followed by catch block ? Core Java
Anonymous
Ans. It should be followed by either catch or finally block.

  Sample Code for Retry in case of exception

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   try   catch   finally  Oracle OCA Test     Accenture  Cognizant (CTS)      basic        frequent

Try 1 Question(s) Test


 Q4. Can we have try and catch blocks within finally ?Core Java
Admin
info@buggybread.com
Ans. Yes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   finally   try   catch   yesno


Frequently asked.
 Q5. When does the finally block gets executed ?Core Java2016-10-31 09:29:10

Ans. A finally block of code always executes, whether or not an exception has occurred.The only time finally won't be called is if you call System.exit() or if the JVM crashes first.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     finally  exception handling  exceptions     Verilogue  Model N  CA Technologies  Mindteck      basic        frequent


 Q6. Can finally block be used without catch ?Core Java
Anonymous
Ans. Yes but should follow "try" block then.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   try   catch   finally   yes-no

Try 1 Question(s) Test


 Q7. How finally used under Exception Handling?Core Java
Admin
info@buggybread.com
Ans. The finally keyword is used to create a block of code that follows a try block. A finally block of code always executes, whether or not an exception has occurred.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   try   finally   basic interview question     Oracle Engineering Group

Try 1 Question(s) Test


 Q8. Will finally be called always if all code has been kept in try block ?Core Java
Admin
info@buggybread.com
Ans. The only time finally won't be called is if you call System.exit() or if the JVM crashes first.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   try   catch   finally   system   system.exit


 Q9. Can finally block throw an exception ?Core Java
Admin
info@buggybread.com
Ans. Yes.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   exceptions   exception handling   finally   yes-no



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. Which of the following is not possible ?

a. try block followed by catch
b. try block followed by finally
c. try block followed by catch block and then finally
d. try block without catch or finally block
Anonymous
Ans. try block without catch or finally block

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     exceptions   java   try-catch   finally

Try 1 Question(s) Test


 Q11. When is the situation when finally section won't execute ?Core Java2017-01-09 12:56:46

Ans. If the process / app is abruptly killed or terminated.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     exception handling  finally     EPAM  Nix Solutions      intermediate

Try 1 Question(s) Test


 Q12. Will finally run if we have return statement and it exits the method early ?Core Java2017-01-10 18:01:40

Ans. finally will execute in all graceful situations - graceful executions as well as graceful exceptions. The only situation when finally block won't execute is when the app is abruptly stopped, killed or unplugged.

  Sample Code for finally

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     finally      Intermediate


 Q13. In which case finally won't get executed ?Core Java
a. in case of exception
b. in case of normal execution
c. in case of return statement before end of try block
d. in case of force program termination

Ans.d. in case of force program termination



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: