Java Specialization Topics: JSF Interview Question
.

Saturday, August 15, 2009

JSF Interview Question

A) What is JSF (Java Server Faces)? JavaServer Faces (JSF) is an application framework containing a rich and robust set of APIs and JSP custom tag libraries to simplify creating user interfaces for web based Java applications. Set of APIs represent user interface components and are responsible for managing their state, handling events, validating input. APIs also define page navigation, internationalization and accessibility. JSF includes JSP custom tag library for including JSF interface within a JSP page.

So JSF offers a flexible and extensible architecture that makes easy creating reusable, complex server side UI components without limiting developer to a particular mark-up language, protocol, or client device by combining the UI component functionality with custom renderers. Here extensible means additional functionality can be given on the top of JSF core i.e. we can customize the functionality and reusable stands for being able to add and reuse components many times in the page.

In the past many web development frameworks came in to existence founded on servlet and jsp. Struts emerged as a standard web application framework. It became framework of choice because it came early in the market and provided necessary features at the time but competitors continued providing additional features that struts lacks. So it became necessary for java to advent new standard framework with a powerful component model. This was the reason for developing JSF technology. So main purpose of developing JSF was to create a collection of APIs for the UI components with the capacity to manage their states, handle events and validation. So JSF can be think of a combination of two frameworks, Struts and Swing. Struts is a popular open source JSP-based Web application framework and Swing is a standard Java user interface framework for desktop applications. Like Struts, JSF provides Web application lifecycle management through a controller servlet (FacesServlet) and like Swing, JSF provides a rich component model complete with event handling and component rendering. JSF also ensures that applications are well designed with greater maintainability by integrating the well established Model-View-Controller (MVC) design pattern into its architecture. So it clearly separates behavior (Model) and presentation (View) in an application. This separation enables a wide range of users Page authors(web-page designers), Application developers, Component writers, Application architects , Tool vendors and allows members of team to focus on their own work only , resulting in division of labor and shorter development cycle. JSF has been developed by Java Community Process(JCP) that is a community of web application experts from different groups like Jakarta Struts, Oracle, Sun, IBM, ATG etc. They all collectively worked together to take the best from existing technologies and removed problems. So their collective effort brought a new technology named Java Server Faces (JSF). Facts about JSF can be summarized as below :

  1. JSF is standard web UI server side component framework for Java.
  2. Built on top of Servlet API.
  3. UI components are stored on the server.
  4. Easy use of third party components.
  5. Event driven programming model.
  6. Events generated by user are handled on the server.
  7. Navigation handling.
  8. Can automatically synchronize UI components .
  9. JSF supports multiple client devices.
  10. JSF has extensible architecture.
  11. International language support.
  12. Extensive tool support (Sun, Oracle , IBM etc.).
  13. Rapid application Development approach.
B) What is the significance of MVC model in JSF? JSF ensures that applications are well designed with greater maintainability by integrating the well established Model-View-Controller (MVC) design pattern into its architecture. So it clearly separates behavior (Model) and presentation of data (View) in an application. UI components representView (Typically in JSP), managed beans represent Model and FacesServlet is the Controller in the JSF framework. All the requests are handled by this controller. Any request passes through and examined by FacesServlet that calls various actions on the model (managed beans). The separation of behavior and presentation enables a wide range of users Page authors( web-page designers), Application developers, Component writers,Application architects , Tool vendors and allows members of team to focus on their own work only , resulting in division of labor and shorter development cycle.
C) Which plays role of controller in JSF? JSF integrates the well established Model-View-Controller (MVC) design pattern into its architecture. The purpose of MVC is to separate data (Model) and presentation of data (View) in an application. User requests are handled centrally by the controller that might result in changes in the model and views. In JSF, UI components represent View layer and managed beans represent Model. FacesServlet is the Controller in the JSF framework. All the requests are handled by this controller. Any request passes through and examined by FacesServlet that calls various actions on the model (managed beans).
D) What is JSF life cycle and its phases? The series of steps followed by an application is called its life cycle. A JSF application typically follows six steps in its life.
  1. Restore view phase
  2. Apply request values phase
  3. Process validations phase
  4. Update model values phase
  5. Invoke application phase
  6. Render response phase
E) What is the role of Renderer in JSF? and justify the statement "JSF supports multiple client devices". After creating JSF components, it is also necessary for each component to be rendered to the client so that it can be visible to the client’s device. Each of the tag gives rise to an associated component. A renderer is a type of class that is responsible for encoding and decoding components. Encoding displays the component while decoding translates the user’s input into components value i.e. transform it into values the component can understand. Now a days there are many devices that are web enabled. So application developers have challenge to develop components that can work across various platforms. For example, if we have an application that works on standard web browser and we want to extend it to make it enable to work on a WAP device. So, to handle this case we need components to be rendered in more than one way. Here JSF can be helpful. This is a simple task for JSF. The solution is to develop separate renderers for the component. JSF components use different renderers depending on the device used.
F) What is Render Kit in JSF? Component classes generally transfer the task of generating output to the renderer. All JSF components follow it. Render kit is a set of related renderers. javax.faces.render.RenderKit is the class which represents the render kit. The default render kit contains renderers for html but it’s up to you to make it for other markup languages. Render kit can implement a skin (a look & feel). Render kit can target a specific device like phone, PC or markup language like HTML, WML, SVG. This is one of the best benefit of JSF because JSF doesn't limit to any device or markup.
G) What is conversion and validation? and how are they related? This is one of the phase of JSF life cycle that happens before binding the component data to the related backing bean in the Update model values phase. Conversion is the process of transforming the component data from String to Java objects and vice versa. For example, an user enters a value (String) in an input component and this value is to store in a Date field in the backing bean then this String value is converted to a java.util.Date value when request is sent to the server and vice versa. This process is called Conversion. Validation is the process of ensuring data contains the expected content. For example, checking the Date value is in MM./dd/YYYY format or any integer value is between 1 to 10. The main purpose of conversion and validation is to ensure the values are of correct type and following the required criteria before updating model data. So this step allows you to focus on business logic rather than working on tedious qualifications of input data such as null checks, length qualifiers, range boundaries, etc.
H) When automatic conversion is supplied by JSF Implementation? JSF implementation automatically converts component data between presentation view and model when the bean property associated with the component is of one of the types supported by the component's data. For example, If a UISelectBoolean component is associated with a bean property of type Boolean, then JSF implementation will automatically convert the data from String to Boolean.
I) Who are the users of JSF technology? JSF is that it has not only been designed for coding experts but for others also Page authors, Component writers etc. Because of integrating MVC model and flexible in its architecture JSF allows a wide range of users :
  1. Page authors : Web designers have experience with graphic design. They can design look and feel of web application in html/jsp using custom tag libraries of JSF.
  2. Application developers : Application developers can integrate this design with UI components. They program objects, event handling, converters, validators.
  3. Component writers : Component developer can build custom UI components because of JSF’s extensible and customizable nature. They can create their own components directly from UI component classes or extending the standard components of JSF.
  4. Application architects : Application architects are responsible for designing web applications. Defining page navigation, ensuring Scalability of application, configuring beans object registration are the key points that an application architect handles.
  5. Tool vendors : JSF is well suited for tool vendors, for example Sun Java Studio Creator application development tool, who provide tools that take advantages of JSF to create UI easier.
J) What are JSF releases? JSF started its journey from version 1.0 and now it has come to its latest version JSF1.2. The listing of versions released so far is :
  1. JSF 1.2 (11 may 2006) - Latest release of JSF specification.
  2. JSF 1.1 (27 may 2004) - Bug fix release. No specification changes. No HTML renderkit changes.
  3. JSF 1.0 (11 mar 2004) - Initial release of JSF specification.

There are many releases of 1.1 and 1.2 and these are listed below showing released date also:

  1. 1.2_04 P01 (20 Mar 2007)
  2. 1.2_04 (5 Mar 2007)
  3. 1.2_02 (25 Aug 2006)
  4. 1.2_01 (14 July 2006)
  5. 1.1_02 (24 Apr 2006)
  6. 1.1_01 (07 Sep 2004)

K) How JSF Fits For Web Applications? JSF has many advantages over other existing frameworks that makes it a better choice for Java web application development. Some of the reasons are below:

  1. Easy creation of UI: It makes easier to create complex UI for an applicaton using jsf tags.Its APIs are layered directly on top of servlet APIs that enables us to use presentation technology other than JSP,creating your own custom components and rendering output for various client devices.
  2. Capacity to handle complexities of UI management: It handles cleanly the complexities of UI management like input validation, component-state management, page navigation, and event handling.
  3. Clean separation between presentation and logic: One of the greatest advantage of jsf is to clearly separate behaviour and presentation in an application. JSF is based on the Model View Controller (MVC) architecture
  4. Shorter development cycle: This separation between logic and presentation enables a wide range of users( from web-page designers to component developers). It allows members of team to focus on their own work only , resulting in division of labour and shorter development cycle.
  5. Standard Java framework: JSF is a Java standard which is being developed through Java Community Process (JCP). Several prominent tool vendors are members of the group and are committed to provide easy to use, visual, and productive develop environments for JavaServer Faces.
  6. An extensible architecture: JSF architecture has been designed to be extensible.Extensible means additional functionality can be given on the top of JSF core i.e. we can customize the functionality. JSF UI components are customizable and reusable elements. You can extend standard components and create your own complex components like stylish calendar, menu bar etc.
  7. Support for multiple client devices: Component developers can extend the component classes to generate their own component tag libraries to support specific client. JSF flexible and extensible architecture allows developers to do so.
  8. Flexible rendering model: Renderer separates the functionality and view of the component. So we can create multiple renderers and give them different functionality to get different appearance of the same component for the same client or different .
  9. International language support: Java has excellent support for internationalization . It allows you to localize messages with user specific locale. A locale is a combination of a country, a language, and a variant code. Java Server Faces adopts this property and let you specify which locale your application supports. So you can display you messages in different languages.
  10. Robust tool support: There are several standard tool vendors like Sun Java Studio Creator who provide robust tools that take advantages of JSF to create server side UI easily.

No comments:

Post a Comment

.