Calling Destructor

Ads
 

Calling Destructor

How can i call destructor in java using System.gc() or manually. Please anyone give me a example program

View Answers

December 20, 2011 at 3:57 PM

Java is a garbage collected language therefore you cannot predict when (or even if) an object will be destroyed. Hence there is no direct equivalent of a destructor.

There is an inherited method called finalize for Garbage Collection.

import java.io.*;
public class FinalizeObject extends FileOutputStream {

// Contructor definition of the FinalizeFileOutputStream class.
public FinalizeFileOutputStream() throws IOException{
super("Rose India"); // call the super class constructor.
}

public static void main(String[] args) throws IOException {

// Create object of FinalizeFileOutputStream class.
FinalizeFileOutputStream objOutstream = new FinalizeFileOutputStream();

// finalize() method call.
objOutstream.finalize();
System.out.print("Stream is closed successfully and connection has "+
"cleaned up to the file.");

}
}

Java Garbage Collection using System.gc()

Ads









Related Tutorials/Questions & Answers:
Calling Destructor
Calling Destructor  How can i call destructor in java using System.gc() or manually. Please anyone give me a example program   Java... if) an object will be destroyed. Hence there is no direct equivalent of a destructor
ModuleNotFoundError: No module named 'destructor'
ModuleNotFoundError: No module named 'destructor'  Hi, My Python... 'destructor' How to remove the ModuleNotFoundError: No module named 'destructor' error? Thanks   Hi, In your python environment you
Advertisements
video calling
video calling  how to implement video calling using java? i am a final year mca student please give me some samplecodes
video calling
video calling  how to implement video calling using java? i am a final year mca student please give me some samplecodes
Calling a function
Calling a function  Hi, I have a function xyz() in php code. When a button is clicked it should execute that particular function for that i have written as <form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
calling servlet from jsp
calling servlet from jsp  how to call a servlet from jsp
calling a java file in java
calling a java file in java  how to call a another java file in java
Calling from JSP
Calling from JSP  how can we call a class file from JSP   Hi, Do you want to call a servlet or a Java Bean through JSP? Please clarify this. For more information, visit the following link: JSP Tutorials Thanks
Calling servlet from servlet .
Calling servlet from servlet .  How to call a servlet from another... ServletException, IOException { System.out.println("Calling another servlet by using...); System.out.println("Calling another servlet by using SendRedirect
calling setInterval() on onclick event
calling setInterval() on onclick event  Hi all, I am trying to call setInterval() on onclick event. But it is executing the code only once. Following is my code. <script type="text/javascript" language="javascript">
Calling Constructor in Spring
Calling Constructor in Spring       In the given example you will be learning about a constructor and how to call a constructor in the Spring. Declaring constructor injection
Calling awt Frame methods from subclass
Calling awt Frame methods from subclass  Calling awt Frame methods from subclass
Calling a jsp page from Servlet
Calling a jsp page from Servlet  How can I do this? Suppose I have jsp page aaa.jsp. From aaa.jsp on form action I have made a call to a servlet xxx.java. In xxx.java I have written code to retrieve data from database through
calling one jsp from another jsp page
calling one jsp from another jsp page  need coding for calling one jsp from another jsp including the xml file.Its urgent
ModuleNotFoundError: No module named 'django-countries-with-calling-codes'
ModuleNotFoundError: No module named 'django-countries-with-calling-codes' ...: ModuleNotFoundError: No module named 'django-countries-with-calling-codes' How to remove the ModuleNotFoundError: No module named 'django-countries-with-calling
ModuleNotFoundError: No module named 'seaborn-calling-function'
ModuleNotFoundError: No module named 'seaborn-calling-function'  Hi...: No module named 'seaborn-calling-function' How to remove the ModuleNotFoundError: No module named 'seaborn-calling-function' error? Thanks  
ModuleNotFoundError: No module named 'sequana-variant-calling'
ModuleNotFoundError: No module named 'sequana-variant-calling'  Hi...: No module named 'sequana-variant-calling' How to remove the ModuleNotFoundError: No module named 'sequana-variant-calling' error? Thanks   
calling from iphone through programitically in iphone
calling from iphone through programitically in iphone  calling from iphone through programitically in iphone please help me my senario is if i click send sms button message should deliver to xyz person and that xyz person make
calling webservices that return complexTypes in android using ksoap2
calling webservices that return complexTypes in android using ksoap2   Can anyone direct me to a site or show me an example ,on how to call a webservice which returns a complexType as the result, in an android app
Error in calling javascript function from java
Error in calling javascript function from java  I am callin javascriot function from applet and getting error netscape.javascript.JSException: Unexpected error: This method should not be used unless loaded from plugin.jar
Calling java class method from javascript
Calling java class method from javascript  I want to call a java class method from javascript. The java class method is like "public String[] getWord()". I want to assign this string array value to a variable in javascript. I
calling servlet from jsp in netbeans ide
calling servlet from jsp in netbeans ide  I have tried to call servlet from jsp code in netbeans for checking the database values . but while running it showing the error that the resource not available. i dono wat mistake i did
pyspark : An error occurred while calling None.org.apache.spark.api.java.JavaSparkContext
pyspark : An error occurred while calling None.org.apache.spark.api.java.JavaSparkContext  Hi I am running pyspark code and it was running fine yesterday. Now its giving the error: pyspark : An error occurred while calling
Calling hibernate query list() method generates errors
Calling hibernate query list() method generates errors  Hello, I'm trying to debug someone's codes. But I am not an expert of hibernate so I'm... grpId){ Query q = getCurrentSession().createQuery("from JobEntity je where
calling webservices that return complexTypes in android using ksoap2
calling webservices that return complexTypes in android using ksoap2   Here's my code for android application,to call aweb service method and return...(); } } } }"); The webservice method i am calling retuns
Implement Java clients calling Web Services
Implement Java clients calling Web Services Prev Chapter 3. Develop clients that access... clients calling Web Services Generating a Java client proxy and a sample
core java ,io operation,calling methods using switch cases
core java ,io operation,calling methods using switch cases  How to create a dictionary program,providing user inputs using io operations with switch cases and providing different options for searching,editing,storing meanings
calling a javascript function by passing multiple values from applet in web application
calling a javascript function by passing multiple values from applet in web application  Hi all, I have a requirement like this, I have to call a javascript function from JApplet by passing 3 values. I am new to Applets
calling one jap page from another jsp page
calling one jap page from another jsp page  i created a button in one jsp page i need to call another jsp page as an action to that button. so how can i call.. plz any one explain. its urgent
calling servlet from JS and return response from servlet to JS
calling servlet from JS and return response from servlet to JS  hello all, I am working on JSP-servlets n MVC.I am facing a problem. on the web page when user clicks on a button i am calling a javascript function(eg myFunc
Creating objects for classes and calling functions of a dll file using JNI
Creating objects for classes and calling functions of a dll file using JNI  Hi all, I am new to JNI. I am having a dll file created by somebody else. In this file, some c++ classes and functions are available. How can we create

Ads