title: What is the 'defer' equivalent for Java
body: <p>This is just a short example of Go code:</p>
  
  <pre><code>package main
  
  import "fmt"
  
  func main() {
      defer fmt.Println("world") //use of keyword 'defer'
  
      fmt.Println("hello")
  }
  </code></pre>
  
  <p>I am finding an equivalent of 'defer' in Java.</p>
  
  <p>Instead of 'defer' I can use</p>
  
  <pre><code>try {
      //do something
  } finally {
      //code using defer
  }
  </code></pre>
  
  <p>Is there any alternative without using try/catch/finally?</p>