Friday, December 04, 2009

Java training notes

Some of my notes from Java training. Some may be of interests to you.

  1. Java final attribute - A blank final attribute must be set in every constructor. Otherwise compiler reports error. -- Legal -- private final int customerId; public Blank(){ customerId=2; }

  1. Overridden method in child class may throw fewer or no exceptions than the exception in parent class

  2. To create an unchecked exception class, extend your exception class from RuntimeException. For checked exception, extend from Exception.

  3. Do not use assertion to check the parameters of a public method.

  4. To enable assertions, use ea or enableassertions control flag in java command java -ea MyApp java -enableassertions MyApp

  5. Java Arrays are objects and cannot grow in size after you declare

  6. Generics eliminate the need for cast

  7. Primitives cannot be stored in EJB component environment.

  8. Which methods are invoked to transition an entity bean from a state of non-existence to a pooled state 1.The EJB Constructor 2.setEntityContext(EntityContext ec)

  9. Only stateless session beans can be implemented as webservice

  10. Instance variables must be explicitly initialized before you use. Otherwise it is a compile error

  11. In subclasses constructors are never inherited. But you can override them.

  12. POJO vs JavaBeans – JavaBeans mandate no argument constructor and getter/setters.

Difference between Message Driven Beans and others

  1. MDB has only bean class

  2. Clients do not access MDB through interface

  3. Most part MDB's are stateless session beans

  4. onMessage is the method called by container for MDB

  5. Mainly used with JMS for async messaging.

EJB

  1. Remote Interface declare business methods

  2. Home Interface declares EJB lifecycle ejbCreate and ejbRemove