• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Finally() method

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hiii

can someone tell me what is the use of finally method in java??
 
Ranch Hand
Posts: 305
Tomcat Server Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gagan Ahuja wrote:hiii

can someone tell me what is the use of finally method in java??



There is no such a method.finally is a block and finalize() is a method.
 
Gagan Ahuja
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
then can yo please elobrate finally block??
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gagan Ahuja wrote:then can yo please elobrate finally block??



http://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html
 
Greenhorn
Posts: 8
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
finalize() is a method from java Object class, when there are no active references to an object "finalize" method will be called by Garbage Collector,
finalize method can be called once on any given object ( by JVM )

finally block

this block can be used to write code, that you want to execute in any case ( meaning irrespective of whether the try block throws some exception or not - the statements in finally block will be always executed unless and until there is a preceding System.exit() call in code)

in the coding scenarios that i have seen, this block is used release all the open connections and resources

just a prototype :

finally
{

if(Connection != null)
connection = null

if(Resultset != null )
Resultset = null
}

Regards
Rahul Parakkat
 
Rahul Parakkat
Greenhorn
Posts: 8
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rahul Parakkat wrote:finalize() is a method from java Object class, when there are no active references to an object "finalize" method will be called by Garbage Collector,
finalize method can be called once on any given object ( by JVM )

finally block

this block can be used to write code, that you want to execute in any case ( meaning irrespective of whether the try block throws some exception or not - the statements in finally block will be always executed unless and until there is a preceding System.exit() call in code)

in the coding scenarios that i have seen, this block is used release all the open connections and resources

just a prototype :

finally
{

if(Connection != null)
connection = null

if(Resultset != null )
Resultset = null
}

Regards
Rahul Parakkat



read the prototype as below : sorry for initial wrong way of closing connection & resultset

just a prototype :

finally
{

if(Connection != null)
connection.close()

if(Resultset != null )
Resultset.close()
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic