- How resource intensive the operation is?
- Does doing it in background thread make sense? (For example, when user asks for archive data of last 5 years in pdf format!).
- What are the technical limitations? Like, controls created in UI thread can not be accessed in another thread.
- What happens if the processing fails?
- Identify possible problems.
- Determine how to respond to each problem.
- Determine when to check for such potential problem.
- Implement exception handling solution based on determination done in steps 1 to 3.
I know this sounds very simple and you are probably going to say "what's new, everyone knows this". But while working in a pressure environment in large scale applications, we often forget to follow these basic steps to determine the right approach. IMHO, it is very important to think about these steps every time you are at cross roads of design and implementation of different modules.
So, as I said, in order to handle exceptions effectively I first try to identify possible problems. By identifying possible problems it helps me add protection in my code by implementing such exception scenarios. For example, I would identify possible compile time exceptions (checked exceptions) and runtime exceptions (unchecked exceptions) that can be thrown from specific module. I use checked exceptions for recoverable conditions and runtime exceptions for programming errors such as processing null values. Once I determine it, I indicate in a program module that it may fail and how it may fail. For example, if I determine that a method getDBConnection() can fail with checked exception of SQLException, I would mention its method signature as following -
public boolean isActiveUser() throws SQLException {
}
My next step would be to decide how to respond to each problem if such exception is thrown. At this point, I think of two possibilities -
- Handle the exception explicitly and implement code to further recover/handle failure or,
- Pass the exception up to the calling module and let it implement solution.
Depending on business case demand and application design, I decide on one of the two approaches. However, it is also better to handle exception explicitly as well as pass it up further to calling module. This allows calling client to implement exception handling but at the same time we can make sure that all the resources consumed in the module that are no longer needed are cleared or made available for garbage collection prior to exiting.
Follow these steps and you will often find yourself free of trouble with exception handling in complex applications.
Here are some of the Java Server Faces (JSF) interview questions that I have compiled. It may be helpful to go through prior to any interview on JSF.
Q. Which are the primary JSF components that you can think of?
A. There are three main components to think of in JSF:
- UIComponent – Defines behavior of a component. UISelectOne can be used to select one value from many values.
- Renderer class – Provides specific rendering. UISelectOne can be rendered as select box or radio button.
- JSP Tag – Associates a renderer with UIComponent and make them usable in JSP. For example - <h:SelectOneMenu>.
Q. Explain request processing life cycle in JSF.
A.
Q. How to get current context in JSF?
A. FacesContext context = FacesContext.getCurrentInstance();
Q. How to get managed bean/component programmatically in JSF?
A.
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();
UBean uBean=app.getVariableResolver().resolveVariable(context,“myBean”);
Q. What are the characteristics of action methods in JSF?A. Its public, takes no arguments and it must return String value.
Q. How to place navigation rules and managed beans outside faces-config.xml?
A.
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/navigation.xml,
/WEB-INF/managed-beans.xml
</param-value>
</context-param>
Q. Explain JSF Event Model.
A.ActionEvent – Applied at application phase.
ValueChangeEvent – Applied at process validation phase.
Q. How to create Converter class in JSF?
A. Following steps needs to be taken -
- Implement javax.faces.convert.Converter.
- Implement methods getAsObject() and getAsString().
- Register converter class in faces-config.xml.
- In view page, use <f:converter>
Q. How to use Spring beans with JSF?
A.
<application>
<variable-resolver> org.springframework.web.jsf.DelegatingVariableResolver
</variable-resolver>
</application>