Difference between Iterator and ListIterator


Using Iterator we can iterate only in forward direction and you cannot add elements while iterating and Here cursor always points to specific index.


public class Example {

  public static void main(String[] args) {

    ArrayList aList = new ArrayList();


    Iterator itr = aList.iterator();




Allows the programmer to traverse the list in either direction, modify the list during iteration, and obtain the iterator’s current position in the list. A ListIterator has no current element; its cursor position always lies between the element that would be returned by a call to previous() and the element that would be returned by a call to next().


public class sample {

  public static void main(String[] args) {
    //create an object of ArrayList
    ArrayList aList = new ArrayList();

    //Add elements to ArrayList object

    //Get an object of ListIterator using listIterator() method
    ListIterator listIterator = aList.listIterator();

    System.out.println(" forward direction using ListIterator");

    System.out.println("reverse direction using ListIterator");


try the above code and get back to me :)

Struts MVC

Struts is MVC based framework developed by Apache. Framework generally provides the basic functionality for a project. Struts provides the set of Action classes, set of tag-libraries, set of Form beans and etc.

Struts combines the most of the design patterns in to a single framework. Struts implements the Single-ton design pattern, Delegate design pattern, Factory Design pattern, Chain of responsibilities.

Struts is Strongly Model View Controller (MVC)based framework MVC fallows the three tier architecture. The model, view and controllers regarding to the Struts are explained as fallows.


View is used to show something to user. Struts allows to use htmls, jsps as view components. To develop the more friendly views struts provided the set of tag libraries. You can download these libraries from the apache site and you can use those into your view components. The set of tag libraries are

struts-html : These tags are replacement of normal html tags. The struts html tags are binds with the form bean properties.

Ex: <html:text property=”userName” />

tag replaces the normal html tag like

<input type=”text” name=”userName” />

struts-bean : These tags are replacement for the jsp action tags. The bean properties are defined with this tags, you can get the bean properties using struts-bean tags.

Ex: <bean:define id=”tempVar” value=”10” />

Above tag defines a variable as ‘tempVar’ and assign 10 to it as string value.

<bean:write name=”Employee” property=”empId” />

Above tag get the value of empId from the Employee form bean.

Struts-logic: These tags are used to write the logical operations. To validate the if conditions or equals conditions you can use these tags.

Ex: <logic:equal name=”empId” value=”100” >Adimin</logic:equal>

Admin is displayed when the empId equals to 100 only.

To get the for loop type iterations you can use the <logic:iterate /> tag.

struts-nested: To display the group of objects you can use the nested tags.

You can implement most of the functionality of above three tags with the nested tags.

Inplace of <bean:write /> you have <nested:write /> and so on…….


Business logic and persistence logic (database dependent logic) will be developed in Model. In struts you can use normal Java beans, DTOs, Dos as models. You can develop the Model layer using other tools also. Struts allows to use Hibernate, spring in the model layer.


Controller is most important concept in the Struts 1.3. In struts ActionServlet acts as Front controller. Each and every request must passes through the ActionServlet. You can change the ActionServlet functionality by extending ActionServlet to your own class.

RequestProcessor class also acts as the controller to process the request. In struts 1.3 Request processor is the ComposableRequestProcessor. It has processXXX() methods. These methods are controls the execution of action classes, controlling of form beans ..etc.

Actions, Dispatch actions, Action Forms , Validator forms ..etc all are come under the controller.

Difference Normal HTML tags and Struts HTML tags

Apache struts provided the struts html tags as the replacement of normal html tags for the Jsps. These Struts html tags are directly bind to the form bean using ActionForm where as normal html tags cannot bind with form beans. HTML tags are static but Struts tags are Dynamic (At the run-time struts tags are called)

But coming to performance half of the code in struts tags is pre-compiled one. If we use normal html tags web container has to load the jsp from the scratch. Where as struts tags loads with the pre-compiled code. So that struts tags improves the performance.

Inner classes in Java

There are four types of classes in Java, those are loosely called as inner classes. Used correctly, inner classes are an elegant and powerful feature of the Java language.

The inner classes are

  1. Static member classes
  2. Member classes
  3. Local classes
  4. Anonymous classes.

Static member classes

A static member class is a class (or interface) defined as a static member of another class. A static method is called a class method, so, by analogy, we could call this type of inner class a “class class,” but this terminology would obviously be confusing. A static member class behaves much like an ordinary top-level class, except that it can access the static members of the class that contains it. Interfaces can be defined as static members of classes.

Member classes

A member class is also defined as a member of an enclosing class, but is not declared with the static modifier. This type of inner class is analogous to an instance method or field. An instance of a member class is always associated with an instance of the enclosing class, and the code of a member class has access to all the fields and methods (both static and non-static) of its enclosing class. There are several features of Java syntax that exist specifically to work with the enclosing instance of a member class. Interfaces can only be defined as static members of a class, not as non-static members.

Local classes:

A local class is a class defined within a block of Java code. Like a local variable, a local class is visible only within that block. Although local classes are not member classes, they are still defined within an enclosing class, so they share many of the features of member classes. Additionally, however, a local class can access any final local variables or parameters that are accessible in the scope of the block that defines the class. Interfaces cannot be defined locally.

Anonymous classes:

An anonymous class is a kind of local class that has no name; it combines the syntax for class definition with the syntax for object instantiation. While a local class definition is a Java statement, an anonymous class definition (and instantiation) is a Java expression, so it can appear as part of a larger expression, such as method invocation. Interfaces cannot be defined anonymously.