Posts

Showing posts from December, 2009

New Features in Java Enterprise Edition 6 (JEE 6)

Latest version of Java Enterprise Edition is focused on eae of development and simplicity. Key goals of this version are Extensibility – supports for additional technologies and frameworks Profiles – support for creating custom profiles based on application scope or requirement. Pruning New Features introduced in this edition are Simplified EJB 3.1 No local business interface – one step further from EJB 3.0 specification, EJB 3.1 specifications removes mandatory business interface Singleton EJB – to share application wide data and support concurrent access. EJB 3.1 can be part of war file directly without creating a separate jar file EAR >>       WAR >>             JSP/Static Pages             WEB_INF >>                   web.xml               lib >>               classes >>                          Servlet and Other classes                     

Java Collection Best Practices

There are the few best practices for Java Collections 1. Decide approximate initial capacity of a collection -  As Collection implementations like ArrayList, HashMap, use Array internally for storing, you can speed up things  by setting initial capacity. 2. Use ArrayLIst, HahMap etc instead of VEctor , Hashtable to avoid synchronization overhead. Even better use array where ever possible. 3. Program to interface instead of implementation – It gives freedom of switching implementation without touching code. For Example : Use List list = new ArrayList(); Avoid : ArrayList list = new ArrayList(); 4. Always return empty collection object instead of null . For Example : Use public List getCustomer(){         //...         return new ArrayList(0); } Avoid : public List getCustomer(){         //...         return null;     } 5. Generally you use a java.lang.Integer or a java.lang.String cl

Implementing default parameter value in Java method

      Those who already familiar with C++ will be missing default parameter values to a function call in Java. Here is the way of implementing same feature in Java.        In Java language , method can accept one or multiple object instance as parameters. Here idea is to pass one object instance instead of multiple primitive type parameters. This object will have default values set to all or some of the object members fields. This explains how to implement the same by example. Here is an example of Simple Draw class as below. Parameter Class : package demo.graphics; public class Option {     public Option() {         //Setting Default Parameters values         color = "BLACK";         lineWidth = 1;         pattern =0;         this.startX = 0;         this.startY = 0;         this.endX = 0;         this.endY = 0;     }     private String color;     private int lineWidth ;     private int startX;