Because Java is a garbage collected language 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
, but this is called entirely at the discretion of the garbage collector. So for classes that need to explicitly tidy up, the convention is to define a close method and use finalize only for sanity checking (i.e. if close has not been called do it now and log an error).
There was a question that spawned in-depth discussion of finalize recently, so that should provide more depth if required…
Related Posts:
- Error java.lang.OutOfMemoryError: GC overhead limit exceeded
- When is the finalize() method called in Java?
- Java GC (Allocation Failure)
- Why cannot the JVM auto expand heap memory to the configured Xmx3072m in linux & jdk1.6.0_32, and FullGC occurs very frequently
- How do I “decompile” Java class files? [closed]
- What is the best way to implement constants in Java?
- What is the reason behind “non-static method cannot be referenced from a static context”?
- What does ” || ” mean in Java? [duplicate]
- max value of integer
- “Error occurred during initialization of VM; Could not reserve enough space for object heap” using -Xmx3G
- “int cannot be dereferenced” in Java
- What is a Key-Value Pair?
- Create ArrayList from array
- How to get current timestamp in string format in Java? “yyyy.MM.dd.HH.mm.ss”
- What is null in Java?
- What is an illegal reflective access?
- Convert Set to List without creating new List
- SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”
- The difference between += and =+
- exception in initializer error in java when using Netbeans
- What does “?” mean in Java?
- MacOS Catalina(v 10.15.3): Error: “chromedriver” cannot be opened because the developer cannot be verified. Unable to launch the chrome browser
- Can I catch multiple Java exceptions in the same catch clause?
- How to get the current date/time in Java
- What is the use of printStackTrace() method in Java?
- How do I limit the number of decimals printed for a double?
- Please initialize the log4j system properly warning
- How to convert jsonString to JSONObject in Java
- how to iterate in List
- > in java and set their values as we do in a normal int a[i][j] matrix type [duplicate]
- Print in new line, java
- How to override equals method in Java
- Java compressing Strings
- How do I call the class’s destructor?
- Can an abstract class have a constructor?
- org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set
- “NoClassDefFoundError: Could not initialize class” error
- Recursive print Factorial
- Recompile with -Xlint:unchecked for detail error in java
- Convert array of strings into a string in Java
- What is Serialization?
- SSL and cert keystore
- “uses unchecked or unsafe operations”
- possible lossy conversion from long to int?
- Guess a number program with Java
- How do I set the proxy to be used by the JVM
- Where to get the tools.jar to use with the Java 8 jdk early release
- int cannot be converted to string?
- How to override toString() properly in Java?
- Returning null in a method whose signature says return int?
- keytool error Keystore was tampered with, or password was incorrect
- Difference between a HashMap and a dictionary ADT
- Converting A String To Hexadecimal In Java
- javax.xml.bind.UnmarshalException: unexpected element (uri:””, local:”Group”)
- Enqueue, Dequeue and ViewQueue in Java
- org.xml.sax.SAXParseException: Content is not allowed in prolog
- Running Command Line in Java
- Working Soap client example
- Simple Dropdown menu in Java
- What is the use of System.in.read()?
- Invalid escape sequence (valid ones are \b \t \n \f \r \” \’ \\ )
- JDK was not found on the computer for NetBeans 6.5
- In Java, how to assign the variable number=Integer.parseInt(args[0]) a value if no argument is passed?
- How to use the command update-alternatives –config java
- How are “mvn clean package” and “mvn clean install” different?
- What is a hash function in java?
- Why are two empty ArrayLists with different generic types equal?
- java.lang.VerifyError: Inconsistent stackmap frames at branch target 421
- tic tac toe java user vs computer
- Java Wait for thread to finish
- How to convert an Instant to a date format?
- equivalent to push() or pop() for arrays?
- JaxbRepresentation gives error “doesnt contain ObjectFactory.class or jaxb.index”
- How do I fix a NoSuchMethodError?
- What is the Java equivalent for LINQ?
- “Expression expected” and “Cannot find symbol” error
- what is update-alternatives command in linux and what is the use of it?
- java: use StringBuilder to insert at the beginning
- Multiple delimiters in Scanner class of Java
- Eclipse Problems View not showing Errors anymore
- C# equivalent to Java’s charAt()?
- unexpected type error
- What does it mean: The serializable class does not declare a static final serialVersionUID field? [duplicate]
- “Cannot be resolved to a type” when attempting to use Scanner
- Converting a 2-3-4 tree into a red black tree
- Generic stack implementation
- Java generating non-repeating random numbers
- java eclipse red exclamation mark
- Java FileOutputStream Create File if not exists
- Configure active profile in SpringBoot via Maven
- Is there any way to program Java on Visual Studio 2015
- Byte and char conversion in Java
- Java “lambda expressions not supported at this language level”
- How to specify filepath in java?
- Issue installing Netbeans in Windows 10: Java SE Development Kit (JDK) was not found on this computer
- dequeue and enqueue methods in queue implementation
- How to specify the default error page in web.xml?
- Exception is never thrown in body of corresponding try statement
- Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 from/to central (http://repo1.maven.org/maven2)
- Using while loop as input validation [duplicate]
- java -version and javac -version showing different versions