Question: I need to convert this program to java. I can handle everything else but the destructor. Now I've already read all over about the GC(garbage collector) and it unreliability. I am thinking why put a destructor for me to convert anyways if there wasn't a way or something.

```
#include<iostream>

using namespace std;

class Timer{
      public:
             Timer();
             ~Timer();
      };
Timer::Timer(){
               cout<<"Install a timer"<<endl;
               }
Timer::~Timer(){
                cout<<"Demolition of timer"<<endl;
                }

class Bomb: public Timer{
      public:
             Bomb();
             ~Bomb();
             };
Bomb::Bomb(){
             cout<<"Install a timer in bomb"<<endl;
             }
Bomb::~Bomb(){
              cout<<"Bomb explode..."<<endl;
              }

int main()
{
    Timer* aTimer = new Timer;
    Bomb* aBomb = new Bomb;
    delete aTimer;
    delete aBomb;

    system("pause");
    return 0;
}

```

So far, what I came up with was this stuff using Eclipse...

```
public class mainting{

    public static void main(String test[])
    {
        timer atimer = new timer();
        bomb abomb = new bomb();

    }
}

public class bomb extends timer {
    public bomb(){
        System.out.println("Install a timer in bomb");

    }

}

public class timer {

    public timer()
    {System.out.println("Install a timer");}

}

```

pretty straight forward I know.

This is the output of the code in C++

```
Install a timer
Install a timer
Install a timer in bomb
Demolition of timer
Bomb exploded
Demolition of timer

```

Answer: 
C++ needs destructors to release resources held by an object. The most frequent need is to dispose of dynamically allocated memory. 

In Java, dynamically allocated memory is disposed automatically by garbage collection. For this, a destructor is not necessary.

Other resources can be disposed of in via an explicit method. You can call this method in a `finally` block, or in Java 7, with a [try-with-resources](http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html). Regardless, consider implementing an interface like `java.io.Closeable` that indicates explicit disposal is required, and provides a method to do so.

For this program, a close translation of the main method would be:

```
public static void main(String test[])
{
    timer atimer = new timer();
    bomb abomb = new bomb();

    try {
       atimer.close();
       abomb.close();
    } catch ( java.io.IOException e ) {
        System.err.println( "An error occurred." );
    }
}

```
You can either use try-with-resources or use the `PreDestroy` annotation.