Upload
srihari4988
View
231
Download
0
Embed Size (px)
Citation preview
8/7/2019 Java Structs
http://slidepdf.com/reader/full/java-structs 1/6
1) What is Struts?
Ans.> Struts is an open source software that helps developers to easily build web application.
-> It is a web page development framework which comprises of Java Servlets, Java Server
Pages(JSP), custom tags, and message resources into a single framework.
->It is also a cooperative platform for development teams as well as independent developers.
2) Explain the components of Struts?
Ans.> Struts is based on the MVC design pattern and its components can be categorized into:
Model: Components like business logic / business processes and data are parts of this.
View: It contains JSP, HTML etc.
Controller: Action Servlet of Struts is part of Controller components which works as front controller tohandle all the requests.
3) What is MVC?
Model-View-Controller ("MVC") is the BluePrints recommended architectural design
pattern for interactive applications.
4) What is the Purpose is MVC?
->The Model/View/Controller architecture was designed to reduce the programming effort required to
build systems that made use of multiple, synchronized presentations of the same data.
->MVC is a design pattern that describes a recurring problem and its solution where the solution is
never exactly the same for every recurrence.
5) How will we make any Of the Message Resources Definitions file available to the Struts
Framework Environment?
Ans.> Message Resources Definitions file are simple property files which consists of messages that
can be used in the struts applications. Message Resources Definitions files can also be added to the
struts-config.xml file using <message-resources /> tag.
E.g. <message-resources parameter="Message Resources" />
6) What is Struts & Validator Framework?
Ans.> Struts Framework provides the functionality to validate the form data. This can be used to
validate data on both the client side as well as server side. It emits the java scripts and can be used
to validate data on the user¶s browser and incase of server side validation, it is done by sub classing
the From Bean with DynaValidatorForm class.
8/7/2019 Java Structs
http://slidepdf.com/reader/full/java-structs 2/6
The Validator framework comes integrated with the Struts Framework and can be used without
doing any extra change in settings.
7) Is struts thread safe?
Ans.> Struts is thread safe as well as thread-dependant. Light-weight Action object handles the
response to a request instead of individual servlets. The Action class is instantiated only once andlets the other requests to be threaded through the original object available. This technique helps to
provide the best possible throughput and conserves resources. A properly-designed application will
exploit this further by routing related operations through a single Action.
8) What are the core classes of the Struts Framework?
Ans.> The core classes of Struts framework are:
ActionServlet is the back bone of the whole web application.
ActionForm is a Java bean that associates one or more ActionMappings.
The business logic is wrapped by the Action class which provides an interface to the Model of the
application.
ActionMapping is used to provide mappings for Objects to Actions.
ActionForward represent the destination for the controller.
9) What are the different kinds of actions in Struts?
Ans.> The different kinds of actions in Struts are as follows:
a. ForwardAction.
b. IncludeAction.
c. DispatchAction.
d. LookupDispatchAction.
e. SwitchAction.
10) Which Core classes is used as a back bone of whole web application?
ActionServlet
11) What are the various Struts tag libraries?
Ans.> The various Struts tag libraries are:
a. Bean tag library ± to access JavaBeans and their properties.
b. HTML tag library - to give standard HTML output, like forms, text boxes, etc.
8/7/2019 Java Structs
http://slidepdf.com/reader/full/java-structs 3/6
c. Logic tag library ± in order to generate conditional output, iteration capabilities and flow
management.
d. Tiles or Template tag library - for those application using tiles.
e. Nested tag library ± in order to use the nested beans in the application.
12) How the exceptions are handled in struts?
Ans.> Exceptions in Struts are handled in two ways:
a. Programmatic exception handling: It is the explicit try/catch blocks in the code that can throw
exception. It works well when any error occurs in the custom value
b. Declarative exception handling: In this we either define <global-exceptions> handling tags in the
struts-config.xml or exception handling tags within <action></action> tag. It works well when error
occurs in custom page and applies only to exceptions thrown by Actions.
13) What is Struts Flow?
Ans.> Struts Flow is a port of Cocoon's Control Flow to Struts in order to allow complex workflow,
like multi-form wizards, which is easily implemented using continuations-capable JavaScript. It
provides the ability to describe the order of web pages that have to be sent to the client, at any given
point of time in an application.
14) What is Purpose of Action Class?
Ans.> The Action Class is a part of the Model. Its purpose is to translate the HttpServletRequest tothe business logic and use the Action, we need to have a Subclass and overwrite the execute()
method, In which all the database/ business processing are done.
The ActionServlet (command) passes the parameterized class to Action Form using the execute()
method and its return type is used by the Struts Framework to forward the request to the file
according the value of the returned ActionForward object.
15) Name Some Problems with Struts?
Ans.> -> Does not work on JDK1.4.0
-> Steep learning curve.
-> Problems on old Application Servers(include Tomcat3.2.1Weblogic 5.1).
-> The only output document is HTMLit didn¶t support the XSL transform technology.(Unless
we modify the source code)
8/7/2019 Java Structs
http://slidepdf.com/reader/full/java-structs 4/6
16) Who makes the Struts?
Answer: Struts is hosted by the Apache Software Foundation(ASF) as part of its Jakarta project, like
Tomcat, Ant and Velocity.
17) Does Struts include its own unit tests?
Answer: YES
Struts currently has two testing environments, to reflect the fact that some things can be tested
statically, and some really need to be done in the environment of a running servlet container.
For static unit tests, we use the JUnit framework. The sources for these tests are in the "src/test"
hierarchy in the source repository, and are executed via the "test.junit" target in the top-level
build.xml file. Such tests are focused on the low-level functionality of individual methods, are
particularly suitable for the static methods in the org.apache.struts.util utility classes. In the test
hierarchy, there are also some "mock object" classes (in the org.apache.struts.mock package) so
that you can package up things that look like servlet API and Struts API objects to pass in as
arguments to such tests.
Another valuable tool is Struts TestCase which provides a useful harness for Action classes that can
be used with JUnit or Cactus.
18) Why it is called Struts?
Answer:
->It's a reference to struts in the architectural sense, a reminder of the nearly invisible pieces that
hold up buildings, houses, and bridges.
->Because the designers want to remind us of the invisible underpinnings that hold up our houses,
buildings, bridges, and ourselves when we are on stilts. This excellent description of Struts reflect
the role the Struts plays in developing web applications.
19) Give the Details of (List) XML files used in Validator Framework?
The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The
validator-rules.xml defines the standard validation routines, these are reusable and used in
validation.xml. to define the form specific validations. The validation.xml defines the validations
applied to a form bean. How you will display validation fail errors on jsp page? - The following tag
displays all the errors: < html:errors/ >
20) Whether Java is 100% Pure OOPS? Give Reasons?
Java is Object oriented But not 100%. Following are the reasons.
1) Everything in java is not Objects. eg: primitive datatypes.
3) All features of OOP lanuage is not fully supported by java. eg: Multiple Inheritance.
Operator Overloading etc.
21) Can a main() method of class be invoked in another class?
8/7/2019 Java Structs
http://slidepdf.com/reader/full/java-structs 5/6
yes,if the main() is declared as public.
22)What is singleton class & it's implementation?
With the Singleton design pattern you can:
Ensure that only one instance of a class is created
Provide a global point of access to the object
Allow multiple instances in the future without affecting a singleton class's clients
//Sample Code
public class SingleInstance {
private static SingleInstance ourInstance = new SingleInstance();
public static SingleInstance getInstance() {
if(null==ourInstance){
ourInstance= new SingleInstance();
}
return ourInstance;
}
private SingleInstance() {
}
}
23) What is a "stateless" protocol ?
Without getting into lengthy debates, it is generally accepted that protocols like HTTP are stateless i.e. there is no retention of state between a
transaction which is a single request response combination.
24) What are the four corner stones of OOPs ?
Abstraction, Encapsulation, Polymorphism and Inheritance.
25) Is it possible to communicate from an applet to servlet and how many ways and how?-
Yes, there are three ways to communicate from an applet to servlet and they are:
a) HTTP Communication(Text-based and object-based)
b) Socket Communication
c) RMI Communication
26)W
ho is loading the init() method of servlet?-
Web server
27) W hat is the difference between Reader/W riter and InputStream/Output Stream?-
The Reader/Writer class is character-oriented and
The InputStream/OutputStream class is byte-oriented.
8/7/2019 Java Structs
http://slidepdf.com/reader/full/java-structs 6/6
28) W hat is the difference between set and list?-
Set stores elements in an unordered way but does not contain duplicate elements, whereas list stores elements in an
ordered way but may contain duplicate elements.
Ques.11> What are the contents of web.xml and struts-config.xml? Explain the difference
between them.
> Ans.> The web.xml file contains the information used by servlets and JSPs, having the description of
the application, mapping information about servlets and URL, JSP configuration information, error
page information without the exceptions.
The struts-config.xml file contains information about struts framework at the time of deploying theweb application. It includes information about form bean, action mappings, controller information
containing the buffer size, content type, etc.
> Ques.12> What is SwitchAction & ForwardAction in struts?
> Ans.> A SwitchAction switches between modules and forwards the control to the URL specified in
the new module. There are two parameters namely page, to which control is forwarded after
switching and prefix that specifies the module to which the control is switched.
A ForwardAction is used to forward a request to the specified URL, represented as a destination to
the controller to which it is sent after the action is completed.
Ques.14> Why is ActionForm a base class rather than an interface?
> Ans.>Making ActionForm a class gives advantage of the single inheritance restriction of Java in
order to make difficult for people to do things that they are not supposed to.
However, if ActionForm is implemented as interface encourages matching of property types to theunderlying business tier, violating one of the important purpose of ActionForm and also encourages
using of existing DAO objects which violates MVC design pattern.