Wednesday, December 25, 2013

Struts

1. Struts2 is configured in web.xml file using filter and filter-mapping tags as below
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <init-param>
         <param-name>config</param-name>
         <param-value>struts-default.xml,struts-plugin.xml,/resources/struts.xml</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
 2. The default location of struts.xml can be changed by giving the desired location in init-param of filter tag as given above.
3. Properties file can be accessed in struts2 using  a  constant in struts.xml as below:-
<constant name="struts.custom.i18n.resources" value="resources/ApplicationResources" />
4. Struts tags can be used in jsp files using taglib directives as below:-
<%@ taglib uri="/struts-tags" prefix="s" %>
 

Monday, December 16, 2013

Collections Framework

This framework has following features
  1. The framework had to be high-performance. The implementations for the fundamental collections (dynamic arrays, linked lists, trees, and hashtables) are highly efficient.
  2. The framework had allows different types of collections to work in a similar manner and with a high degree of interoperability.
  3. Extending and/or adapting a collection is very easy.
Collections frameworks contain the following:
  1. Interfaces: These are abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of their representation. In object-oriented languages, interfaces generally form a hierarchy. These are the basic interfaces in this framework
    1. Collection Interface
      1. It is at the top of hierarchy.
    2. List Interface:-
      1.  It extends collection interface
      2. Elements can be inserted or accessed by their position in the list, using a zero-based index.
      3. A list may contain duplicate elements.
      4. Implementations are ArrayList and LinkedList
    3. Set:-
      1. A Set is a Collection that cannot contain duplicate elements.
      2. Null can not be used. 
      3. Implementations are HashSet
    4. SortedSet
      1. The SortedSet interface extends Set and declares the behavior of a set sorted in ascending order
      2. Null can not be used. \
      3. Implementations are TreeSet
    5. Map
      1.  Given a key and a value, you can store the value in a Map object. After the value is stored, you can retrieve it by using its key
      2. Null can not be used.   
      3. Implementations are HashMap
    6. MapEntry
      1. It enables you to work with a map entry that is the set of map keys
    7.  SortedMap
      1. The SortedMap interface extends Map. It ensures that the entries are maintained in ascending key order
      2. Implementations are TreeMap.
    8. Enumeration
      1. It helps to deal with one element at a time for any collection
      2. It is almost obsolete and is replaced by iterator interface.

  2. Implementations, i.e., Classes: These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures.The main implementation classes of each of the collection interfaces are  given above already in the interface definitions
  3. Algorithms: These are the methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the same method can be used on many different implementations of the appropriate collection interface.
ArrayList and Vector:-
  1. Synchronization - ArrayList is not thread-safe whereas Vector is thread-safe. In Vector class each method like add(), get(int i) is surrounded with a synchronized block and thus making Vector class thread-safe.
  2. Data growth -Internally, both the ArrayList and Vector hold onto their contents using an Array. When an element is inserted into an ArrayList or a Vector, the object will need to expand its internal array if it runs out of room. A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent.
Synchronizing a non-synchronized Collection
  1. Collection.synchronizedList(List list)
  2. Collection.synchronizedCollection(Collection collection)
  3. Collection.synchronizedMap(Map map)
HashMap and HashTable:-
  1. HashMap is not synchronized whereas HashTable is.
  2. HaspMap permits null values in both key and value
  3. HaspMap is 
List:- Classes are ArrayList, LinkedList, Vector
  1. ArrayList :- resizable array and is indexed, non sysnchronized. It grows 50% of its size when more elements are added
  2. LinkedList :- double linked list and is indexed, get and set decreases performance while add and remove are fast and is non sysnchronized
  3. Vector : - It is synchronized and doubles its size when more elements are added. It also implements Queque interface so more methods like offer, peak, poll etc are available.
Set :- Classes are HashSet, LinkedHashSet and TreeSet
  1. HashSet: -Allows one null, order is not maintained.
  2. LinkedHashSet :- Order is maintained, one null allowed
  3. TreeSet :- Order is maintained, null is not allowed
Map :- Classes are HashMap, HashTable and TreeMap
  1. HashMap : It allows ONLY one null key and multiple null values. Ordered on the basis of keys. It is not synschronized
  2. TreeMap :- Null keys are not allowed at all but null values are.
  3. HashTable :- It is synchronized but unordered and null keys and null values are not allowed at all 

Resource: http://www.docjar.com/html/api/java/util/

Collection Interface:

List Interface


   

SpringBoot Application Event Listeners

When a spring boot application starts few events occurs in below order ApplicationStartingEvent ApplicationEnvironmentPreparedEvent Applicat...