FRESHERSHOME
Freshers Forum

can any one tell me the basic difference b/w destructor in c,c++ &finalizer in java?

This is a discussion on can any one tell me the basic difference b/w destructor in c,c++ &finalizer in java? within the JAVA forums, part of the Languages category; computer programming...


Go Back   Jobs in India Forum > Programming > Languages > JAVA

Notices

JAVA JAVA Discussion Forum, Jave Related help

 
Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2008, 06:38 PM
YahooHoo
 
Join Date: Feb 2008
Posts: 1
Default can any one tell me the basic difference b/w destructor in c,c++ &finalizer in java?

computer programming
__________________
Powered by Yahoo!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 02-26-2008, 06:39 PM
YahooHoo
 
Join Date: Feb 2008
Posts: 1
Default

Destructors don't exist in C, just in C++.

I believe you need destructors in C++ to do things like deallocate memory for arrays your objects generated dynamically.

In Java, all your memory gets deallocated automatically when you stop using it. You use finalizers to stop using system resources, like file streams and network sockets. There are usually better ways to do this (like closing a stream in the finally clause of the try-catch block the stream is used in).

Only use finalizers when necessary.

I don't think you're supposed to use C++ destructors to stop using system resources, but you probably could if you wanted to.
__________________
Powered by Yahoo!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 02-26-2008, 06:40 PM
YahooHoo
 
Join Date: Feb 2008
Posts: 1
Default

destructor in c/ c++

As opposed to a constructor, a destructor is called when a program has finished using an instance of an object. A destructor does the cleaning behind the scenes. Like the default constructor, the compiler always create a default destructor if you don't create one. Like the default constructor, a destructor also has the same name as its object. This time, the name of the destructor starts with a tilde.

and in destructor in Java

the finalize() method is called before the object is to gced. Note that the invocation of finalize is not gantenteed to be called at any paticular time. And may not be called if System.exit(int) is invoked before the object is gced. If you want an operation to peform on exit use Runtime.addShutdownHook method. If you want to add a destructor to an existing object that you are not implementing you can use a PhantomReference to get notified when the object is dead.

To add a destructor use:

protected void finalize() throws Throwable
{
//do finalization here
super.finalize(); //not necessary if extending Object.
}
__________________
Powered by Yahoo!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
tell, basic, difference, destructor, finalizer, java

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump

Sitemap
Jobs by Location: Advertising and Marketing Jobs - IT Software Jobs - Walk-in Jobs - BPO Jobs - Government Jobs - Sales / BD Jobs - Tele Communication Jobs App Programming - Network Admin

Jobs By Location: Jobs in Bangalore - Jobs In India - Jobs in Delhi - Jobs in Hyderabad - Jobs in Kochi - Jobs in Mumbai - Jobs in Trivandrum - Jobs in pune - Jobs in Jonida - Jobs in Chennai - Jobs in Coimbator

Jobs Type: Full Time Jobs - Part Time Jobs
Latest Jobs - Accounting Jobs - Engineering Jobs - IT Jobs - Walkins - How to Face Interview - HR Round Tips - Career Info - Guide For Freshers - Apply for Jobs - Future Studies - Jobs Forums - Freshers IT Software Salary Details


All times are GMT +6.5. The time now is 06:02 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
FreshersHome.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62