What is JSF?


JSF stands for Java Server Faces and it is an industry standard and a server side user interface component framework for building component-based user interfaces for web applications. JSF has set of pre-assembled User Interface (UI).

It is event-driven programming model. By that it means that JSF has all necessary code for event handling and component organization. Application programmers can concentrate on application logic rather sending effort on these issues. It has component model that enables third-party components to be added like AJAX.

Difference between Iterator and ListIterator


Iterator:

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

Example:

 
public class Example {

  public static void main(String[] args) {

    ArrayList aList = new ArrayList();

    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("5");

    Iterator itr = aList.iterator();

    while(itr.hasNext())
      System.out.println(itr.next());

  }
}


ListIterator:

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().

Example:

public class sample {

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

    //Add elements to ArrayList object
    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("5");

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

    System.out.println(" forward direction using ListIterator");
    while(listIterator.hasNext())
      System.out.println(listIterator.next());

    System.out.println("reverse direction using ListIterator");
    while(listIterator.hasPrevious())
      System.out.println(listIterator.previous());

  }
}

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:

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…….

Model:

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:

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.

Enabling javascript in browsers


To enable java script in you browser, please follow the instructions below:

Internet Explorer (6.0)

1. Select ‘Tools’ from the top menu
2. Choose ‘Internet Options’
3. Click on the ‘Security’ tab
4. Click on ‘Custom Level’
5. Scroll down until you see section labled ‘Scripting’
6. Under ‘Active Scripting’, select ‘Enable’ and click OK

Netscape Navigator (4.8)

1. Select ‘Edit’ from the top menu
2. Choose ‘Preferences’
3. Choose ‘Advanced’
4. Choose ‘Scripts & Plugins’
5. Select the ‘Enable JavaScript’ checkbox and click OK

Mozilla Firefox (1.0)

1. Select ‘Tools’ from the top menu
2. Choose ‘Options’
3. Choose ‘Web Features’ from the left navigation
4. Select the checkbox next to ‘Enable JavaScript’ and click OK

Mozilla Firefox (1.5)

1. Select ‘Tools’ from the top menu
2. Choose ‘Options’
3. Choose ‘Content’ from the top navigation
4. Select the checkbox next to ‘Enable JavaScript’ and click OK

Apple Safari (1.0)

1. Select ‘Safari’ from the top menu
2. Choose ‘Preferences’
3. Choose ‘Security’
4. Select the checkbox next to ‘Enable JavaScript’

Numeric Validation in javaScript


var isNS4 = (navigator.appName==”Netscape”)?1:0;
function checkCharacter(event){
if(!isNS4){
if(event.keyCode == 8 || event.keyCode == 0 ) return true;
if(event.keyCode < 46 || event.keyCode > 57 ) {
event.returnValue = false;
}
}
else{
if(event.which == 8 || event.which == 0 ) return true;
if(event.which < 46 || event.which > 57 ) {
return false;
}
}
}