Intuit Most Frequently Asked Latest Advanced Java Interview Questions Answers
Can I Have An Action Without A Form?
Yes. If your Action does not need any data and it does not need to make any data available to the view or controller component that it forwards to, it doesn't need a form. A good example of an Action with no ActionForm is the LogoffAction in the struts example application
<action path="/logoff"
type="org.apache.struts.webapp.example.LogoffAction">
<forward name="success" path="/index.jsp"/>
</action>
This action needs no data other than the user's session, which it can get from the Request, and it doesn't need to prepare any view elements for display, so it does not need a form.
However, you cannot use the <html:form> tag without an ActionForm. Even if you want to use the <html:form> tag with a simple Action that does not require input, the tag will expect you to use some type of ActionForm, even if it is an empty subclass without any properties.
Can You Give Me A Simple Example Of Using The Requiredif Validator Rule?
First off, there's an even newer Validator rule called validwhen, which is almost certainly what you want to use, since it is much easier and more powerful. It will be available in the first release after 1.1 ships.
The example shown below could be coded with validwhen as
<form name="medicalStatusForm">
<field
property="pregnancyTest" depends="validwhen">
<arg0 key="medicalStatusForm.pregnancyTest.label"/>
<var>
<var-name>test</var-name>
<var-value>((((sex == 'm') OR (sex == 'M'))
AND (*this* == null)) OR (*this* != null))</test>
</var>
</field>
Let's assume you have a medical information form
with three fields,
sex, pregnancyTest, and testResult. If sex is 'f' or 'F',
pregnancyTest is required. If pregnancyTest is not blank,
testResult is required. The entry in your validation.xml
file would look like this
<form name="medicalStatusForm">
<field
property="pregnancyTest" depends="requiredif">
<arg0 key="medicalStatusForm.pregnancyTest.label"/>
<var>
<var-name>field[0]</var-name>
<var-value>sex</var-value>
</var>
<var>
<var-name>fieldTest[0]</var-name>
<var-value>EQUAL</var-value>
</var>
<var>
<var-name>fieldValue[0]</var-name>
<var-value>F</var-value>
</var>
<var>
<var-name>field[1]</var-name>
<var-value>sex</var-value>
</var>
<var>
<var-name>fieldTest[1]</var-name>
<var-value>EQUAL</var-value>
</var>
<var>
<var-name>fieldValue[1]</var-name>
<var-value>f</var-value>
</var>
<var>
<var-name>fieldJoin</var-name>
<var-value>OR</var-value>
</var>
</field>
<field
property="testResult" depends="requiredif">
<arg0 key="medicalStatusForm.testResult.label"/>
<var>
<var-name>field[0]</var-name>
<var-value>pregnancyTest</var-value>
</var>
<var>
<var-name>fieldTest[0]</var-name>
<var-value>NOTNULL</var-value>
</var>
</field>
</form>
When Is The Best Time To Validate Input?
This is an excellent question. Let's step back a second and think about a typical mid to large size application. If we start from the back end and work toward the view we have
1) Database: Most modern databases are going to validate for required fields, duplicate records, security constraints, etc.
2) Business Logic: Here you are going to check for valid data relationships and things that make sense for the particular problem you are triing to solve.
... This is where struts comes into the picture, by now the system should be pretty well bulletproof. What we are going to do is make validation friendlier and informative. Rember it is OK to have duplicate validations...
3) ActionErrors validate(ActionMapping map, HttpServletRequest req) is where you can do your validation and feed back to the view, information required to correct any errors. validate is run after the form has been reset and after the ActionForm properties have been set from corresponding view based input. Also remember you can turn validation off with validate="false" in the action mapping in the struts-config.xml. This is done by returning an ActionErrors collection with messages from your ApplicationResources.properties file.
Here you have access to the request so you can see what kinds of action is being requested to fine tune your validations. The <html:error> tag allows you to dump all errors on your page or a particular error associated with a particular property. The input attribute of the struts-config.xml action allows you to send validation errors to a particular jsp / html / tile page.
4) You can have the system perform low level validations and client side feedback using a ValidatorForm or its derivatives. This will generate javascript and give instant feedback to the user for simple data entry errors. You code your validations in the validator-rules.xml file. A working knowledge of regular expressions is necessary to use this feature effectively.
How Can I Avoid Validating A Form Before Data Is Entered?
The simplest way is to have two actions. The first one has the job of setting the form data, i.e. a blank registration screen. The second action in our writes the registration data to the database. Struts would take care of invoking the validation and returning the user to the correct screen if validation was not complete.
The EditRegistration action in the struts example application illustrates this
< action path="/editRegistration">
type="org.apache.struts.webapp.example.EditRegistrationAction"
attribute="registrationForm"
scope="request"
validate="false">
<forward name="success path="/registration.jsp"/>
</action>
When the /editRegistration action is invoked, a registrationForm is created and added to the request, but its validate method is not called. The default value of the validate attribute is true, so if you do not want an action to trigger form validation, you need to remember to add this attribute and set it to false.
Declarative Exception Handling
If you have developed web applications long enough, you will realize a recurring pattern emerges: when the backend (e.g. the EJB tier) throws you an exception, you nearly always need to display an error page corresponding to the type of that exception. Sooner or later, you will come up with a mechanism to use a lookup table (e.g. an HashMap) to lookup an error page from the exception class.
Struts 1.1 now provides a similar but more powerful mechanism to declare exception handling. In Struts 1.1, you can declare in the struts-config.xml the associations between an exception class and an exception handler. Using the default exception handler included in Struts, you can also specify the path of the error pages. With this information, Struts will automatically forward to the specified pages when an uncaught exception is thrown from an Action.
Like other facilities in Struts, the exception handlers are pluggable. You can write and define your own handler classes if needed.
What Is Hibernate?
Hibernate is a powerful, high performance object/relational persistence and query service.
This lets the users to develop persistent classes following object-oriented principles such as association, inheritance, polymorphism, composition, and collections.
What Is Orm?
ORM stands for Object/Relational mapping. It is the programmed and translucent perseverance of objects in a Java application in to the tables of a relational database using the metadata that describes the mapping between the objects and the database. It works by transforming the data from one representation to another.
What Does An Orm Solution Comprises Of?
• It should have an API for performing basic CRUD (Create, Read, Update, Delete) operations on objects of persistent classes.
• Should have a language or an API for specifying queries that refer to the classes and the properties of classes.
• An ability for specifying mapping metadata.
• It should have a technique for ORM implementation to interact with transactional objects to perform dirty checking, lazy association fetching, and other optimization functions.
What Are The Different Levels Of Orm Quality?
There are four levels defined for ORM quality.
i. Pure relational
ii. Light object mapping
iii. Medium object mapping
iv. Full object mapping.
What Is A Pure Relational Orm?
The entire application, including the user interface, is designed around the relational model and SQL-based relational operations.
What Is A Meant By Light Object Mapping?
The entities are represented as classes that are mapped manually to the relational tables. The code is hidden from the business logic using specific design patterns. This approach is successful for applications with a less number of entities, or applications with common, metadata-driven data models. This approach is most known to all.
What Is A Meant By Medium Object Mapping?
The application is designed around an object model. The SQL code is generated at build time. And the associations between objects are supported by the persistence mechanism, and queries are specified using an object-oriented expression language. This is best suited for medium-sized applications with some complex transactions. Used when the mapping exceeds 25 different database products at a time.
What Is Message Driven Beam?
An enterprise bean that is an asynchronous message consumer. A message-driven bean has no state for a specific client, but its instance variables can contain state across the handling of client messages, including an open database connection and an object reference to an EJB object. A client accesses a message-driven bean by sending messages to the destination for which the bean is a message listener.
What Is Session Bean. What Are The Various Types Of Session Bean?
SessionBeans typically are used to represent a client they are of two types
Stateful Session Beans : they maintain conversational state between subsequest calls by a client.
Stateless Session Bean : consider this as a servlet equivalent in EJB. It is just used to service clients regardless of state and does not maintain any state.
What Is The Difference Between Stateful Session Bean And Stateless Session Bean
Stateful session beans have the passivated and Active state which the Stateless bean does not have.
What Are The Call Back Methods In Session Bean?
Session bean callback methods differ whether it is Stateless or stateful Session bean they are.
Stateless Session Bean
1. setSessionContext()
2. ejbCreate()
3. ejbRemove()
Stateful Session Bean
1. setSessionContext()
2.ejbCreate()
3.ejbPassivate()
4.ejbActivate()
5.ejbRemove()
When You Will Chose Stateful Session Bean And Stateless Session Bean
stateful session bean is used when we need to maintain the client state . Where stateless session bean will not have a client state it will be in pool. Example of statefull session is Shoping cart site where we need to maintain the client state .
What Is The Relationship Between Enterprise Javabeans And Javabeans?
Enterprise JavaBeans extends the JavaBeans component model to handle the needs of transactional business applications.
JavaBeans is a component model for visual construction of reusable components for the Java platform. Enterprise JavaBeans extends JavaBeans to middle-tier/server side business applications. The extensions that Enterprise JavaBeans adds to JavaBeans include support for transactions, state management, and deployment time attributes.
Although applications deploying the Enterprise JavaBeans architecture are independent from the underlying communication protocol, the Enterprise JavaBeans architecture specifies how communication among components maps into the underlying communication protocols, such as CORBA/IIOP.
How To Implement A Bound Property In Your Bean Application?
To implement a bound property in the application, follow these steps
IBM plans to ship the JavaBeans Migration Assistant for ActiveX in Taligent's Visual Age, WebRunner Toolkit, and Visual Age for Java development tools. This will allow developers to utilize a common component model that may be leveraged by a wide range of tools, including the IBM Visual Age for Java family.
Why Would A Developer Need The Javabeans Migration Assistant For Activex?
Many of the capabilities that are so exciting to JavaBeans developers are not available on ActiveX, or are incomplete. There is, therefore, a need for a set of conversion conventions and tools designed to convert desktop ActiveX components into JavaBeans components. The resulting Beans will be usable in both in new network savvy e-business applications as well as traditional desktop applications, includingActiveX containers. Developers and customers benefit from the advantages offered by JavaBeans by simply leveraging their current investments in ActiveX.
Can Javabeans Use Dcom As Its Network Model?
JavaBeans works with any network model (i.e., to communicate between components across the network), including CORBA, DCOM, etc. JavaBeans integrates well with CORBA IDL, which is an excellent solution for customers in a heterogeneous distributed computing environment with platform independent components. However, we recommend RMI for Java to Java inter-object communication.
Can Both Java Applets And Javabeans Components Use The Infobus?
Yes.
Javabeans Has Mechanisms Like Bound Properties For Data Transfer Between Components. Why Is The Infobus Necessary?
JavaBeans mechanisms, such as bound properties, are very useful in cases where the type of data to be communicated can be hard-coded into the source and target components. The InfoBus adds additional features required for more dynamic data interchange. These can be cases where communication is driven by the content of the data and where the nature of the data to be exchanged is determined at runtime.
Is Infobus Easy To Use?
Using InfoBus aware components, such as the ESuite components from Lotus, users can easily construct powerful data driven applications. No programming or scripting is required: simple parameters are used to establish connections to databases and to select data for processing. For developers creating InfoBus components, InfoBus offers a straightforward API compatible in style with other features of JavaBeans.
Can I Have An Action Without A Form?
Yes. If your Action does not need any data and it does not need to make any data available to the view or controller component that it forwards to, it doesn't need a form. A good example of an Action with no ActionForm is the LogoffAction in the struts example application
<action path="/logoff"
type="org.apache.struts.webapp.example.LogoffAction">
<forward name="success" path="/index.jsp"/>
</action>
This action needs no data other than the user's session, which it can get from the Request, and it doesn't need to prepare any view elements for display, so it does not need a form.
However, you cannot use the <html:form> tag without an ActionForm. Even if you want to use the <html:form> tag with a simple Action that does not require input, the tag will expect you to use some type of ActionForm, even if it is an empty subclass without any properties.
Can You Give Me A Simple Example Of Using The Requiredif Validator Rule?
First off, there's an even newer Validator rule called validwhen, which is almost certainly what you want to use, since it is much easier and more powerful. It will be available in the first release after 1.1 ships.
The example shown below could be coded with validwhen as
<form name="medicalStatusForm">
<field
property="pregnancyTest" depends="validwhen">
<arg0 key="medicalStatusForm.pregnancyTest.label"/>
<var>
<var-name>test</var-name>
<var-value>((((sex == 'm') OR (sex == 'M'))
AND (*this* == null)) OR (*this* != null))</test>
</var>
</field>
Let's assume you have a medical information form
with three fields,
sex, pregnancyTest, and testResult. If sex is 'f' or 'F',
pregnancyTest is required. If pregnancyTest is not blank,
testResult is required. The entry in your validation.xml
file would look like this
<form name="medicalStatusForm">
<field
property="pregnancyTest" depends="requiredif">
<arg0 key="medicalStatusForm.pregnancyTest.label"/>
<var>
<var-name>field[0]</var-name>
<var-value>sex</var-value>
</var>
<var>
<var-name>fieldTest[0]</var-name>
<var-value>EQUAL</var-value>
</var>
<var>
<var-name>fieldValue[0]</var-name>
<var-value>F</var-value>
</var>
<var>
<var-name>field[1]</var-name>
<var-value>sex</var-value>
</var>
<var>
<var-name>fieldTest[1]</var-name>
<var-value>EQUAL</var-value>
</var>
<var>
<var-name>fieldValue[1]</var-name>
<var-value>f</var-value>
</var>
<var>
<var-name>fieldJoin</var-name>
<var-value>OR</var-value>
</var>
</field>
<field
property="testResult" depends="requiredif">
<arg0 key="medicalStatusForm.testResult.label"/>
<var>
<var-name>field[0]</var-name>
<var-value>pregnancyTest</var-value>
</var>
<var>
<var-name>fieldTest[0]</var-name>
<var-value>NOTNULL</var-value>
</var>
</field>
</form>
Intuit Most Frequently Asked Latest Advanced Java Interview Questions Answers |
When Is The Best Time To Validate Input?
This is an excellent question. Let's step back a second and think about a typical mid to large size application. If we start from the back end and work toward the view we have
1) Database: Most modern databases are going to validate for required fields, duplicate records, security constraints, etc.
2) Business Logic: Here you are going to check for valid data relationships and things that make sense for the particular problem you are triing to solve.
... This is where struts comes into the picture, by now the system should be pretty well bulletproof. What we are going to do is make validation friendlier and informative. Rember it is OK to have duplicate validations...
3) ActionErrors validate(ActionMapping map, HttpServletRequest req) is where you can do your validation and feed back to the view, information required to correct any errors. validate is run after the form has been reset and after the ActionForm properties have been set from corresponding view based input. Also remember you can turn validation off with validate="false" in the action mapping in the struts-config.xml. This is done by returning an ActionErrors collection with messages from your ApplicationResources.properties file.
Here you have access to the request so you can see what kinds of action is being requested to fine tune your validations. The <html:error> tag allows you to dump all errors on your page or a particular error associated with a particular property. The input attribute of the struts-config.xml action allows you to send validation errors to a particular jsp / html / tile page.
4) You can have the system perform low level validations and client side feedback using a ValidatorForm or its derivatives. This will generate javascript and give instant feedback to the user for simple data entry errors. You code your validations in the validator-rules.xml file. A working knowledge of regular expressions is necessary to use this feature effectively.
How Can I Avoid Validating A Form Before Data Is Entered?
The simplest way is to have two actions. The first one has the job of setting the form data, i.e. a blank registration screen. The second action in our writes the registration data to the database. Struts would take care of invoking the validation and returning the user to the correct screen if validation was not complete.
The EditRegistration action in the struts example application illustrates this
< action path="/editRegistration">
type="org.apache.struts.webapp.example.EditRegistrationAction"
attribute="registrationForm"
scope="request"
validate="false">
<forward name="success path="/registration.jsp"/>
</action>
When the /editRegistration action is invoked, a registrationForm is created and added to the request, but its validate method is not called. The default value of the validate attribute is true, so if you do not want an action to trigger form validation, you need to remember to add this attribute and set it to false.
Declarative Exception Handling
If you have developed web applications long enough, you will realize a recurring pattern emerges: when the backend (e.g. the EJB tier) throws you an exception, you nearly always need to display an error page corresponding to the type of that exception. Sooner or later, you will come up with a mechanism to use a lookup table (e.g. an HashMap) to lookup an error page from the exception class.
Struts 1.1 now provides a similar but more powerful mechanism to declare exception handling. In Struts 1.1, you can declare in the struts-config.xml the associations between an exception class and an exception handler. Using the default exception handler included in Struts, you can also specify the path of the error pages. With this information, Struts will automatically forward to the specified pages when an uncaught exception is thrown from an Action.
Like other facilities in Struts, the exception handlers are pluggable. You can write and define your own handler classes if needed.
What Is Hibernate?
Hibernate is a powerful, high performance object/relational persistence and query service.
This lets the users to develop persistent classes following object-oriented principles such as association, inheritance, polymorphism, composition, and collections.
What Is Orm?
ORM stands for Object/Relational mapping. It is the programmed and translucent perseverance of objects in a Java application in to the tables of a relational database using the metadata that describes the mapping between the objects and the database. It works by transforming the data from one representation to another.
What Does An Orm Solution Comprises Of?
• It should have an API for performing basic CRUD (Create, Read, Update, Delete) operations on objects of persistent classes.
• Should have a language or an API for specifying queries that refer to the classes and the properties of classes.
• An ability for specifying mapping metadata.
• It should have a technique for ORM implementation to interact with transactional objects to perform dirty checking, lazy association fetching, and other optimization functions.
What Are The Different Levels Of Orm Quality?
There are four levels defined for ORM quality.
i. Pure relational
ii. Light object mapping
iii. Medium object mapping
iv. Full object mapping.
What Is A Pure Relational Orm?
The entire application, including the user interface, is designed around the relational model and SQL-based relational operations.
What Is A Meant By Light Object Mapping?
The entities are represented as classes that are mapped manually to the relational tables. The code is hidden from the business logic using specific design patterns. This approach is successful for applications with a less number of entities, or applications with common, metadata-driven data models. This approach is most known to all.
What Is A Meant By Medium Object Mapping?
The application is designed around an object model. The SQL code is generated at build time. And the associations between objects are supported by the persistence mechanism, and queries are specified using an object-oriented expression language. This is best suited for medium-sized applications with some complex transactions. Used when the mapping exceeds 25 different database products at a time.
What Is Message Driven Beam?
An enterprise bean that is an asynchronous message consumer. A message-driven bean has no state for a specific client, but its instance variables can contain state across the handling of client messages, including an open database connection and an object reference to an EJB object. A client accesses a message-driven bean by sending messages to the destination for which the bean is a message listener.
What Is Session Bean. What Are The Various Types Of Session Bean?
SessionBeans typically are used to represent a client they are of two types
Stateful Session Beans : they maintain conversational state between subsequest calls by a client.
Stateless Session Bean : consider this as a servlet equivalent in EJB. It is just used to service clients regardless of state and does not maintain any state.
What Is The Difference Between Stateful Session Bean And Stateless Session Bean
Stateful session beans have the passivated and Active state which the Stateless bean does not have.
What Are The Call Back Methods In Session Bean?
Session bean callback methods differ whether it is Stateless or stateful Session bean they are.
Stateless Session Bean
1. setSessionContext()
2. ejbCreate()
3. ejbRemove()
Stateful Session Bean
1. setSessionContext()
2.ejbCreate()
3.ejbPassivate()
4.ejbActivate()
5.ejbRemove()
When You Will Chose Stateful Session Bean And Stateless Session Bean
stateful session bean is used when we need to maintain the client state . Where stateless session bean will not have a client state it will be in pool. Example of statefull session is Shoping cart site where we need to maintain the client state .
What Is The Relationship Between Enterprise Javabeans And Javabeans?
Enterprise JavaBeans extends the JavaBeans component model to handle the needs of transactional business applications.
JavaBeans is a component model for visual construction of reusable components for the Java platform. Enterprise JavaBeans extends JavaBeans to middle-tier/server side business applications. The extensions that Enterprise JavaBeans adds to JavaBeans include support for transactions, state management, and deployment time attributes.
Although applications deploying the Enterprise JavaBeans architecture are independent from the underlying communication protocol, the Enterprise JavaBeans architecture specifies how communication among components maps into the underlying communication protocols, such as CORBA/IIOP.
How To Implement A Bound Property In Your Bean Application?
To implement a bound property in the application, follow these steps
- Import the java.beans package. This gives you access to the PropertyChangeSupport class.
- Instantiate a PropertyChangeSupport object. This object maintains the property change listener list and fires property change events. You can also make your class a PropertyChangeSupport subclass.
- Implement methods to maintain the property change listener list. Since a PropertyChangeSupport subclass implements these methods, you merely wrap calls to the property-change support object's methods.
- Modify a property's set method to fire a property change event when the property is changed.
IBM plans to ship the JavaBeans Migration Assistant for ActiveX in Taligent's Visual Age, WebRunner Toolkit, and Visual Age for Java development tools. This will allow developers to utilize a common component model that may be leveraged by a wide range of tools, including the IBM Visual Age for Java family.
Why Would A Developer Need The Javabeans Migration Assistant For Activex?
Many of the capabilities that are so exciting to JavaBeans developers are not available on ActiveX, or are incomplete. There is, therefore, a need for a set of conversion conventions and tools designed to convert desktop ActiveX components into JavaBeans components. The resulting Beans will be usable in both in new network savvy e-business applications as well as traditional desktop applications, includingActiveX containers. Developers and customers benefit from the advantages offered by JavaBeans by simply leveraging their current investments in ActiveX.
Can Javabeans Use Dcom As Its Network Model?
JavaBeans works with any network model (i.e., to communicate between components across the network), including CORBA, DCOM, etc. JavaBeans integrates well with CORBA IDL, which is an excellent solution for customers in a heterogeneous distributed computing environment with platform independent components. However, we recommend RMI for Java to Java inter-object communication.
Can Both Java Applets And Javabeans Components Use The Infobus?
Yes.
Javabeans Has Mechanisms Like Bound Properties For Data Transfer Between Components. Why Is The Infobus Necessary?
JavaBeans mechanisms, such as bound properties, are very useful in cases where the type of data to be communicated can be hard-coded into the source and target components. The InfoBus adds additional features required for more dynamic data interchange. These can be cases where communication is driven by the content of the data and where the nature of the data to be exchanged is determined at runtime.
Is Infobus Easy To Use?
Using InfoBus aware components, such as the ESuite components from Lotus, users can easily construct powerful data driven applications. No programming or scripting is required: simple parameters are used to establish connections to databases and to select data for processing. For developers creating InfoBus components, InfoBus offers a straightforward API compatible in style with other features of JavaBeans.
Post a Comment