Posts

Showing posts from October, 2012

finalize() method in java

protected void finalize () throws Throwable {} every class inherits the  finalize()  method from java.lang.Object the method is called by the garbage collector when it determines no more references to the object exist the Object finalize method performs no actions but it may be overridden by any class normally it should be overridden to clean-up non-Java resources ie closing a file if overridding  finalize()  it is good programming practice to use a try-catch-finally statement and to always call  super.finalize() . This is a safety measure to ensure you do not inadvertently miss closing a resource used by the objects calling class protected void finalize () throws Throwable { try { close (); // close open files } finally { super . finalize (); } } any exception thrown by  finalize()  during garbage collection halts the finalization but is otherwise ignored finalize()  is ne...

Plain Old Java Objects (POJO)

What is a POJO? "A POJO is a simple ordinary java object that does not extends classes or implements interfaces from any frameworks or APIs" The term "POJO" is mainly used to denote a Java object which does not follow any of the major Java object models, conventions, or frameworks.  A POJO is a Java object that doesn't implement any special interfaces  ,extends classes, defined in frameworks and APIs.  Ideally speaking, a POJO is a Java object not bound by any restriction other than those forced by the Java Language Specification. i.e a  POJO  should not  have to. Extend prespecified classes, as in public class Foo extends javax. servlet . http . HttpServlet { ... Implement prespecified interfaces, as in public class Bar implements javax. ejb . EntityBean { ... Contain prespecified annotations, as in @javax. persistence . Entity public class Baz { ... However, due to technical difficulties and other reasons, many ...