What is the basically use of finally while we know it
is always executed but why?

Answers were Sorted based on User's Feedback



What is the basically use of finally while we know it is always executed but why?..

Answer / reshma

Using finally one can close the resources such as file
handler or a database connection. It ia good to maintain
the internal state of an object.

Is This Answer Correct ?    13 Yes 2 No

What is the basically use of finally while we know it is always executed but why?..

Answer / muffy.jad@gmail.com

The finally block is used to ensure resources are recovered
regardless of any problems that may occur.

finally is important because it allows the programmer to
guarantee the release of memory regardless of what happens
in the try block

finally is necessary when you need to set something other
than memory back to its original state.

Is This Answer Correct ?    11 Yes 0 No

What is the basically use of finally while we know it is always executed but why?..

Answer / sivadasan

Finally block always execute, its not consider whether an
exception is raised or not. Once try block is executed
means finally will be executed.

Finally block is necessary, often sufficient to execute
some important things its nothing but connection close
stmt..

system.exit(0); given in try catch block means finally
block will not be executed.

Is This Answer Correct ?    4 Yes 0 No

What is the basically use of finally while we know it is always executed but why?..

Answer / srinu

In finally block writing the code of clean up code i.e
means release the database connection,close the file.The
finally block complusary be executed block when ever
exception raised or not all ways execute this finally block

Note:
The following write statement write in try or catch block
it will not execute
System.error(0);

Is This Answer Correct ?    2 Yes 0 No

What is the basically use of finally while we know it is always executed but why?..

Answer / guest

it is must after a try statement

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More Core Java Interview Questions

How Array List can be Serialized.

7 Answers   Polaris,


Explain the selection sort algorithm and state its time complexity?

0 Answers   Flextronics,


Explain about varargs in java?

0 Answers  


Can finally block be used without a catch?

0 Answers  


Variables used in a switch statement can be used with which datatypes?

0 Answers  






What is pojo class in java?

0 Answers  


What is the difference between the file and randomaccessfile classes?

0 Answers  


Can you inherit from an abstract class java?

0 Answers  


What is object data type?

0 Answers  


what is meta-Inf?

2 Answers   Polaris,


Is it possible to do method overloading and overriding at a time

3 Answers   L&T,


Explain listiterator and methods in listiterator?

0 Answers  


Categories