Posts

Which one is better Struts2 or Spring?

In Struts 2 you can develop only web based application. However, spring’s usefulness is not limited to server-side development. Any java application can benefit from spring in terms of simplicity, testability, and loose coupling. Comparing features: ·          both allow configuration via XML or annotations ·          both follow the MVC pattern ·          both have interceptors for cross-cutting concerns ·          both allow for "controller" style action classes ·          both are stable and mature ·          both have actions that are POJOs and return Strings as results ·          both making unit testing simple API of Spring MVC has better documentation. The Struts2 guides and tutoria...

What is StackOverflowError, when it occurs with example?

When a program attempts to use more space than is available on the call stack the stack is said to overflow, typically resulting in a program crash. A call stack is a stack data structure that stores information about the active method of a program. A stack overflow occurs when an application recurses too deeply. One cause of StackOverflowError is a method calling itself without exit condition. Example: /**  *  * @author Navindra Jha  */ public class Main {     public static void main(String[] args) {         new Friend().hello();     } } class Friend {     public String hello() {         return "Room: " + this.hello();     } } Output: Exception in thread "main" java.lang.StackOverflowError

Difference between Heap and Stack memory, why can’t we store everything in stack?

“In Java, Stack memory holds primitives and method invocations and heap memory is used to store objects.” The basic difference between stack and heap is the life cycle of the values. Stack values only exist within the scope of the function they are created in. Once it returns, they are discarded. Heap values however exist on the heap. They are created at some point in time, and destructed at another (either by GC or manually, depending on the language/runtime). Now Java only stores primitives on the stack. This keeps the stack small and helps keeping individual stack frames small, thus allowing more nested calls. Objects are created on the heap, and only references (which in turn are primitives) are passed around on the stack. So if you create an object, it is put on the heap, with all the variables that belong to it, so that it can persist after the function call returns. When a method is called , a frame is created on the top of stack. Once a method has completed e...

Diffrerence between ActionContext & ValueStack in struts 2

OGNL stands for Object-Graph Navigation Language; it is an expression language for getting and setting properties of Java objects. You use the same expression for both getting and setting the value of a property. The struts 2 framework uses a standard naming context to evaluate OGNL expressions. In expression, the properties of the root object can be referenced without any special "marker" notion. References to other objects are marked with a pound sign (#). The framework sets the OGNL context to be our ActionContext, and the value stack to be the OGNL root object. (The value stack is a set of several objects, but to OGNL it appears to be a single object.) Along with the value stack, the framework places other objects in the ActionContext, including Maps representing the application, session, and request contexts. These objects coexist in the ActionContext, alongside the value stack (our OGNL root). The Action instance is always pushed onto the value stack. Bec...

Inheritance of static members

A class that is derived from another class is called a   subclass   (also a   derived class ,   extended class , or   child class ). The class from which the subclass is derived is called a   superclass   (also a   base class   or a   parent class ). Excepting   Object , which has no superclass, every class has one and only one direct superclass (single inheritance). In the absence of any other explicit superclass, every class is implicitly a subclass of   Object . The idea of inheritance is simple but powerful: When you want to create a new class and there is already a class that includes some of the code that you want, you can derive your new class from the existing class. In doing this, you can reuse the fields and methods of the existing class without having to write (and debug!) them yourself. A subclass inherits all the   members including static member   (fields, methods, and nested classes) from its...

what is Ajax, Why use Ajax and How to implement in Java

Some use for Ajax interactions are following: 1. Real time form data validation e.g. UserID, EmailID, Serial No, Postal Code etc. 2. Load on demand e.g. fetch data in background, allowing browser load page quickly 3. Sophisticated user interface controls and effects e.g. control such as calendar, trees, menus, data tables ,rich text editor. 4. Refreshing data and server path e.g. such as scores, stock quotes, weather, or application specific data. 5. Partial submit 6. Page as an application e.g. single page application that look and feels like desktop application. XMLHttpRequest: A JavaScript object, it allow client-side script to perform HTTP Request, and it will parse an xml server response. Ajax stands for asynchronous; when you send that HTTP request you don’t want the browser to hand around waiting for the server to respond. Instead, you want to continue reading to the user’s interaction with the page and deal with the server’s response when it eventu...

Working Example of Hibernate with explanation

A Hibernate has mainly three components: 1. Hibernate Mapping File (*.hbm.xml) 2. Hibernate Configuration File (*.cfg.xml) 3. Persistence  Object (*.class) Mapping File: Mapping  the Contact Object to the Database Contact table The file contact.hbm.xml is used to map Contact Object to the Contact table in the database.  Here is the code for contact.hbm.xml: contact table must has ID, firstname, lastname, email field as describe in mapping file <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated Jan 1, 2002 12:34:16 AM by Hibernate Tools 3.2.1.GA --> <hibernate-mapping>     <class name="hibernateappexample.Contact" table="contact" catalog="stu">         <id name="id" type="int">             ...