Showing posts with label String Buffer. Show all posts
Showing posts with label String Buffer. Show all posts

Saturday, 18 February 2012

Java Interview Questions: - Mention the life-cycle phases of JSF (Java Server Faces)?

Following is the brief Life-cycle phases of JSF (Java Server Faces) asked during Java interview questions.

Restore View : A request comes through the FacesServlet controller. The controller examines the request and extracts the view ID, which is determined by the name of the JSP page.

Apply request values: The purpose of the apply request values phase is for each component to retrieve its current state. The components must first be retrieved or created from the Faces Context object, followed by their values.

Process validations: In this phase, each component will have its values validated against the application's validation rules.

Update model values: In this phase JSF updates the actual values of the server-side model, by updating the properties of your backing beans.

Invoke application: In this phase the JSF controller invokes the application to handle Form submissions.
Render response: In this phase JSF displays the view with all of its components in their current state.

See the following video by using String or String Buffer performance increases asked during java Interview: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Monday, 17 October 2011

Java/J2EE interview questions: - Is using StringBuffer always yields better performance than concatenation using +?

No, String Buffer need not yield a good performance over String concatenation using "+".

The type of concatenation plays a major role in deciding performance. If the concatenation can be completely resolved at coimpile time then String concatenation using + will yield better results
On the other hand if concatenation is done at run time using StringBuffer is more advisable, since StringBuffer objects are resolved at run time

Following are the two programs one showing compile time resolution and other run time and thus showing where StringBuffer will be useful.

Compile time resolution: 


This program takes String literals and performs concatenation using + as well as StringBuffer. Since the String literals could be resolved at compile time itself, this indicates a case of compile time resolution.


Code is self explanatory with proper comments given where ever required.
On executing the above code we get following result

Result:


Concatenation using + takes 0 millisecs
Concatenation using StringBuffer takes 63 millisecs
Performance using concatenation using + better than StringBuffer concatenation.

Conclusion: Since the above case if of compile time resolution performance using + concatenation yields a better result.

Run Time resolution:


Just a small modification to compile time code shown above can give us run time case for further analysis.

We change the concatenation used above to String conResult =""; conResult = conResult +"Welcome to the World of Java" +"Performance" +"@"+"questpond";

a similar change is done in StringBuffer . code snippet after change will look like





Result :


Concatenation using + takes 47 millisecs
Concatenation using StringBuffer takes 32 millisecs
Performance using concatenation using StringBuffer better than + concatenation.



Conclusion : the above case clearly shows StringBuffer giving more performance as compared to + concatenation at run time.

Overall final conclusion: Prefer StringBuffer whenever run time resolution concatenation is involved
View the following video on J2EE Design Pattern - Service Locator: -



Get more Java/J2EE interview questions