of the currently active methods. If the exception propagates all the way up to the top-most main method without a matching catch block being found, a textual description of the exception is written to the standard output stream. The statements within the finally block are always executed after the try and catch blocks, whether or not an exception was thrown and even if a return statement was reached. Such blocks are useful for providing clean-up code that is guaranteed to always be executed. The catch and finally blocks are optional, but at least one or the other must be present following the try block. try-with-resources statements try-with-resources statements are a special type of try-catch-finally statements introduced as an implementation of the dispose pattern in Java SE 7. In a try-with-resources statement the try keyword is followed by initialization of one or more resources that are released automatically when the try block execution is finished. Resources must implement java.lang.AutoCloseable. try-with-resources statements are not required to have a catch or finally block unlike normal try-catch-finally statements. try (FileOutputStream fos = new FileOutputStream("filename"); XMLEncoder xEnc = new XMLEncoder(fos)) { xEnc.writeObject(object); } catch (IOException ex) { Logger.getLogger(Serializer.class.getName()).log(Level.SEVERE, null, ex); } Since Java 9 it is possible to use already declared variables: FileOutputStream fos = new FileOutputStream("filename"); XMLEncoder xEnc = new XMLEncoder(fos); try (fos; xEnc) { xEnc.writeObject(object); } catch (IOException ex) { Logger.getLogger(Serializer.class.getName()).log(Level.SEVERE, null, ex); } throw statement The throw statement is used to throw an exception and end the execution of the block or method. The thrown exception instance is written after the throw statement. void methodThrowingExceptions(Object obj) { if (obj == null) { // Throws exception of NullPointerException type throw new NullPointerException(); } // Will not be called, if object is null doSomethingWithObject(obj); } Thread concurrency control Java has built-in tools for multi-thread programming. For the purposes of thread synchronization the synchronized statement is included in Java language. To make a code block synchronized, it is preceded by the synchronized keyword followed by the lock object inside the brackets. When the executing thread reaches the synchronized block, it acquires a mutual exclusion lock, executes the block, then releases the lock. No threads may enter this block until the lock is released. Any non-null reference type may be used as the lock. /* Acquires lock on someObject. It must be of a reference type and must be non-null */ synchronized (someObject) { // Synchronized