Saturday, June 18, 2011

10 sureshot Struts2 interview questions

1. What is struts? What is the need of using it ??
Struts is a framework. A framework is reusable component that can be used for producing custom applications.Struts combines Java Servlets, Jsp, custom tags and message resource files into a unified framework.

2. What is difference between Struts 1.0 and 1.1 ??
1. Request Processor Clas.2. perform() is replaced by execute() in Action class3. Dynamic Actions Form (DynaActionForm)4. chages in Struts-config.xml

3. What is MVC2 and Model2 models ??
Model2 : In Model2 we have client tier as Jsp, Controller is servlet, and javaBean is Model. But in this Java bean and controller both are tightly coupled and controller receives the UI parameters. but in MVC these are loosely coupled and controller has nothing to do with the business logic. The UI (Client Tier) parameters are automatically transmitted to the business logic bean called as ActionForm. So Model2 isa project specific model while MVC is project independent.

4. What are the core classes of strutrs ??
ActionForm, Action, ActionMapping, ActionForwad

5.Can you explain ActionServlet, Action Class and ActionForm and their usage ??
ActionServlet : The class org.apache.struts.action.ActionServlet is the called ActionServlet. It play a role of controller.All the request goes throgh controller.Controller is responsible to handle all the incoming request. The controller receive the request from the client(browser), invoke a business opeartion and coordinate with view that is return to the client.ActionForm : It is a Javabean that extends org.apche..struts.action.ActionForm. ActionForm maintains the session state for web application and the ActionForm object is automatically populated on the server side with data entered from the form on hte client side. Action Class : It is part of Model and is wrapped around the business logic. the purpose of this class is to transalate HttpServletRequst to the business logic . To use the Action, we need to subclass and override execute() method.

6.What is message Resource Definition File??
M.R.D. file are simple .properties file contain the messages that can be used to display the message on client(browser) window. It ca be specific to locale like for i18n. It can be added in struts-config.xml through tag.ex

7. What is the usage of execute and validate method in struts???Execute : It is called by the controller when a request is received from the client . the controller creates a instance of the Action class if one does not already exists.The framework will create only a single instance of each Action classes.
public ActionForward execute(ActionMapping pMapping, ActionForm pForm, HttpServletRequest pRequest, HttpServeltResponse pResponse)
Valiate : This method is called by the controller for performing input validations andreturning back any detected errors to the controller.
public ActionErrors valiate(ActionMapping pMapping,HttpServletRequest pRequest)

8. What is the difference between ActionForm and DynaActionform ??In struts 1.0 ActionForm is used to populate the html tags data. But if there is any changes in Jsp like adding a input box it also requires changes in ActionForm. In struts 1.1 and above we can specify a Action form as a DynaActionForm and defines the properties in xml rather than writing them in java with getter nad setter method.


9. How many types of Actions are in struts ??there are Mainly 2 Main actions1) Bridge Actions : It contains ForwardAction and IncludeAction2) Base Actions : It contains DispatchAction LookupDispatchAction SwitchAction and BaseAction
Contributed by santosh shetgarThe important Dispatchers that struts provides includes : DispatchAction ActionDispatcher LookupDispatchAction and MappingDispatchAction.
DispatchAction: In this type of aggregation the action class must extend DispatchAction class as shown.
public final class CRUDDispatchAction extends DispatchAction {
public ActionForward create(ActionMapping mapping ActionForm form HttpServletRequest request HttpServletResponse response) throws Exception {return (mapping.findForward( success ));}...
and the action mapping will be as

in your jsp you can call this action as
Create...
Observe that the above class extends DispatchAction and so you cannot use this method if your class already extends your (some) super class (eg. the class where the session is validated/invalidated). Here the user has to send a query string variable (methodToCall) to set the action name to call.
ActionDispatcher: This flavor of aggregation is same as DispatchAction except that we need not extend ActionDispatcher so we can use this method even if our class extends a super class. The following code snippet shows this scenario.
public final class CRUDActionDispatcher extends Action {
protected ActionDispatcher dispatcher new ActionDispatcher(this ActionDispatcher.DEFAULT_FLAVOR);
public ActionForward execute(ActionMapping mapping ActionForm form HttpServletRequest request HttpServletResponse response) throws Exception {return dispatcher.execute(mapping form request response);
The DEFAULT_FLAVOR field suggests that the default parameter is method if none is specified as parameter in struts-config.xml (eg . methodToCall).ActionDispatcher flavor also needs methodToCall parameter to be set (using hidden variable or a query string) as in case of DispatchAction.
LookupDispatchAction: This type of aggregation is useful in situations where in you have multiple submit buttons in a single form. The class must extend LookupDispatchAction. However the great thing about this type is that its java script free. That means you need not set any hidden variables or pass query string however you must use submit buttons as shown.
... The example Action class will be as follows
public class CRUDLookUpDispatchAction extends LookupDispatchAction {
protected Map getKeyMethodMap() {Map map new HashMap();map.put( button.create create );
return map;}public ActionForward create(ActionMapping mapping ActionForm form HttpServletRequest request HttpServletResponse response) throws Exception {return (mapping.findForward( success ));}Observe the getKeyMethodMap() method. The submit button names are specified in a Map and their keys comes from MessageResources file. Struts picks up the name from this file and redirects it to the value specified in the Map. The calling code in jsp however has multiple submit buttons only differing in their names.
MappingDispatchAction: This aggregation extends MappingDispatchAction class. This is the most useful type among the four types available. But as seen in other cases you can use this type only when your action does not extend any other action. The good thing about this type is that the action mappings can differ and so need not be the same as in all other cases. To illustrate this consider the below mappings.

Notice that in the first action mapping there is no form bean while in the second the bean name is specified. This means that the user has the flexibility to change the mapping according to his needs and hence not been contained to use a constant mapping for all the CRUD actions. Note that in all the other types of aggregations we must use the same mapping for all the CRUD actions.

10. Can describe struts-config.xml and its functionality ??




Tuesday, February 1, 2011

15 Basic Reusable (Important) Components for Product Development

Basic Reusable(Important) components for a Product Development:

1. License Manager - If it is a licensable product
2. Utility Manager (File/String/Common/Thread/Collection)
3. Thread Manager (With Thread Pool)
4. Code generator - for generating redundant code
5. Base Framework
6. Logger Framework ( or Common Framework Integrated with open source logging APIs)
7. Code Static analysis tool
8. Performance Measurement Framework
9. Authentication Manager
10. Database Connection Manager
11. DataTransfer framework (FTP/TCP/UDP/HTTP)
12. Versioning Manager
13. Transaction Processor framework(Transaction Manager)
14. DAO Manager
15. RequestHandler (WebRequest Gateway) - If it have a web based communication

7 Most important Product Management's Activities

1. Market Planning
2. Competitive Market Analysis
3. Requirement/Enhancement/Features Analysis
4. Prioritization
5. Release Planning
6. RoadMap Planning
7. Performance Monitoring

Sunday, January 23, 2011

Commonly used Http Codes

[sourcecode language="css"]
200 = OK
204 = No Content
302 = Found
305 = Use Proxy
400 = Bad Request
401 = Unauthorized
402 = Payment Required
403 = Forbidden
404 = Not Found
405 = Method Not Allowed
407 = Proxy Authentication Required
408 = Request Timeout
414 = Request URI Too Large
415 = Unsupported Media Type
500 = Internal Server Error
501 = Not Implemented
502 = Bad Gateway
503 = service Unavailable
504 = Gateway Timeout
505 = Http Version Not Supported


[/sourcecode]

Fibonacci Series

Find the fibonacci series based on the input number. If number is 8 then it should print like 1 1 2 3 5 8 13 21
package myrnd;

public class Fibonacci {

public static void main(String[] args) {

int num = 8;
int a, b = 0, c = 1;
for (int i = 0; i < num; i++) {
System.out.print(c+" ");
a = b;
b = c;
c = a + b;
}
}
}

Reverse of a number

Find the reverse of a number. eg if input number is 786 then output should be 687.
[sourcecode language="java"]
package myrnd;

public class ReverseNo {

// 786 : reverse : 687
public static void main(String[] args) {
int n = 78890;
int result = 0;
int remainder;
while (n > 0) {
remainder = n % 10;
result = result * 10 + remainder;
n = n / 10;
}
System.out.println("Result:" + result);
}
}

[/sourcecode]

Factorial of a number

[sourcecode language="java"]
package myrnd;

public class Factorial {

public static void main(String[] args) {
int a = 5;
int result = 1;
while (a > 0) {
result *= a;
a--;
}
System.out.println("result is:" + result);
// using recursion.
System.out.println("factorial :" + factorial(5));
}

// another way using recursion.
public static int factorial(int n) {
if (n > 1) {
return n * factorial(n - 1);
}
return n;
}
}

[/sourcecode]