Saturday, March 24, 2012

GlassFish and MyEclipse and Eclipse support...

For the time and energy I spent to install the Release candidate for Europa, I must admit that paying a few dollars for MyEclipse is definitely the right investment to do (although I am still missing a complete installer for Mac OSX, and a GlassFish/MyEclipse co-Bundle that would be installable in one shot).

I enjoyed the JSP editor (and renderer), as well as an extensive JavaScript support that should play well with our Ajax jMaki  components (that are also available for Eclipse).
There are still a few issues in the Java EE 5 support of MyEclipse (for example, one cannot create JPA entity beans in a Web Application, or no pure Java EE 5 Web Services support -Axis is the only supported stack-, or that the fact you need to touch files like web.xml or ejb-jar.xml or application.xml to trigger a redeployment for exploded directories -when these files are now optional in the latest Java EE 5 specification which is all about ease of development and replacement of those xml files into Java annotations)-, but all I can say is that for people who want an Eclipse based IDE to do Java EE 5 development (and target the GlassFish application server), MyEclipse is certainly a very good option and worth the investment. Very soon, MyEclipse will switch to Eclipse Europa platform and the latest good stuff from WTP 2.0.

Registering GlassFish in MyEclipse is very easy, and deployment of Java EE 5 applications to it is simple:

Having said that, for people who have the freedom to look at a solution which is not Eclipse based, NetBeans 5.5.1 and the coming NetBeans 6.0 are also offering advanced (and complete) Java EE 5 support, including JSF, JPA, Web Services and more. NetBeans also updates automatically the GlassFish specific descriptors when needed and transparently.

In conclusion, it is good to see that there is a wide range of tools targeting Java EE 5, and it's best implementation so far: GlassFish:-)


Configure WebLogic in MyEclipse

Please follow the steps to configure Weblogic in MyEclipse
 Before configuring in MyEclipse, first we need to configure the server and domain in Configuration Wizard
1) Go to Start ->  Bea Web Logic -> Configuration Wizard
This will open a configuration wizard for you
2) Select “Create a new WebLogic Configuration” and Click next
3) Select “Basic WebLogic Server Domain” and Click Next
4) Select “Express” and click next
5) Here, give username and password
6) click next -> next ->
7) By default, the domai name is mydomain , If you want you can change in the bottom right corner  “Configuration Name”
8) Select Create and It will create a domain for you.
9) You can see that in Start -> BEA Weblogic -> User Projects

 Steps to follow in MYEclipse
1)      Go to  Windows – > Preferences -> Select MyEclipse
2)      Expand that and select Application Servers – > WebLogic -> Weblogic 8
  1. Select on WebLogic 8.x and fill the following

      b) Select JDK and select jdk 1.4 from bea directory
     c) now you can start the server

How Spring MVC Works

In this we will see the request flow for the spring framework. We will also show you the request flow diagram illustrating the working of Spring MVC module.
The Spring MVC modules comes with the Spring Framework distribution. The Spring MVC modules of the Spring Framework well integrates with rest of the framework. This modules is also very extensible.
Spring MVC is based on the MVC design pattern. Here is the list of key classes of Spring MVC.
  • DispatcherServlet
    The DispatcherServlet is  configured in the web.xml file and required URL patterns are mapped to this Servlet. It works as the front controller and handle all the request from the user.
  • ModelAndView
    This class works as the holder for both Model and View in the Spring MVC.
  • SimpleFormController
    The SimpleFormController is the Concrete FormController implementation. It provides the configurable form and success views, and an onSubmit chain for convenient overriding. Automatically resubmits to the form view in case of validation errors, and renders the success view in case of a valid submission.
Simplified Spring MVC architecture diagram
Following diagram shows the simplified architecture of Spring MVC:
Spring MVC Architecture, Spring MVC request flow
Let's understand the sequences of the events happens when a request is received by the Spring MVC. Following events happens when DispatcherServlet receives are request:
  1.  The DispatcherServlet configured in web.xml file receives the request.
  2. The DispatcherServlet finds the appropriate Controller with the help of HandlerMapping and then invokes associated Controller.
  3. Then the Controller executes the logic business logic (if written by the programmer) and then returns ModeAndView object to the DispatcherServlet.
  4. The DispatcherServlet determines the view from the ModelAndView object.
  5. Then the DispatcherServlet passes the model object to the View.
  6.  The View is rendered and the Dispatcher Servlet sends the output to the Servlet container. Finally Servlet Container sends the result back to the user.
Request flow in Spring MVC
Spring MVC is request driven and DispatcherServlet handles the request from client and then dispatches the request to controllers. It tightly integrates with the Spring IoC container and allows the developers to use every features of Spring framework.
The following diagram illustrates the request flow in Spring MVC.
Spring MVC Request flow
Request handling steps in Spring MVC
  1. Client access some URL on the server.
  2. The Spring Front Controller (DispatcherServlet) intercepts the Request. After receiving the request it finds the appropriate Handler Mappings.
  3. The Handle Mappings maps the client request to appropriate Controller. In this process framework reads the configuration information from the configuration file or from the annotated controller list. Then DispatcherServlet dispatch the request to the appropriate Controller. The Handler Adapters involves in this process.
  4. Then the Controller processes the Client Request, it executes the logic defined in the Controller method and finally returns the ModelAndView object back to the Front Controller.
  5. Based on the values in the ModelAndView Controller resolves the actual view, which can be JSP, Velocity, FreeMaker, Jasper or any other configured view resolver.
  6. Then the selected view is rendered and output is generated in the form of HttpServletResponse. Finally Controller sends the response to the Servlet container, which sends the output to the user.
Controllers hierarchy in Spring MVC
In this we will will understand the controllers hierarchy in Spring MVC Module. The Spring MVC module provides a lot of flexibility to easily develop MVC based web applications. It provides many controllers that can be used to achieve different jobs.
Spring MVC module is based on the MVC design pattern. The main components involved are DispatcherServlet, Controller and Views. In Spring MVC DispatcherServlet plays very important role. It handles the user request and delegates it with Controller. Following diagram shows the very simplified architecture:

In this Spring MVC, DispatcherServlet works as the controller and it delegates the request to the Controller. Developers extends the abstract controller provided by the framework and writes the business logic there. The actual business related processing is done in the Controller.
 Spring MVC provides many abstract controllers, which is designed for specific tasks. Here is the list of anstract controllers that comes with the Spring MVC module:
  1. SimpleFormController
  2. AbstractController
  3. AbstractCommandController
  4. CancellableFormController
  5. AbstractCommandController
  6. MultiActionController
  7. ParameterizableViewController
  8. ServletForwardingController
  9. ServletWrappingController
  10. UrlFilenameViewController
  11. AbstractController
  12. AbstractCommandController
  13. SimpleFormController
  14. CancellableFormController.
Following diagram shows the Controllers hierarchy in Spring MVC:
Spring MVC Controller hierarchy
In the next sections we will be learning about all these controllers. We will also provide you the examples codes illustrating the usage of these controllers.

Friday, March 23, 2012

Spring PPT'S

Saturday, March 17, 2012

MVC 1 vs MVC2


Difference Between MVC 1 & MVC 2   
                    MVC  1     
                        MVC 2
MVC1 associates the presentation logic with the business logic.

MVC 2 isolates or disassociates the presentation logic from business logic

In MVC1, only one component is responsible for receiving request and sending response.
In MVC2, there is separate components for receiving and  sending response. i.e. Controller & View.In
MVC 1, business logic and presentation Logic is combined so web designer and web developer cant work simulateously.
Since both logics are separate that's why designer and developer can work together.
Doesn't support reusability of application components.
Reusability of components
In MVC 1, controller and model,both are JSP.
While controller is servlet and model is java class.
In MVC1 there is tight coupling between page and model as data access is usually done using Custom tag or through java bean call. 
In MVC2 architecture there is only one controller which receives all the request for the application and is responsible for taking appropriate action in response to each request.

Struts 1 vs Struts 2

FeatureStruts 1Struts 2
Action classesStruts 1 requires Action classes to extend an abstract base class. A common problem in Struts 1 is programming to abstract classes instead of interfaces.An Struts 2 Action may implement an Action interface, along with other interfaces to enable optional and custom services. Struts 2 provides a base ActionSupport class to implement commonly used interfaces. Albeit, the Action interface is not required. Any POJO object with a execute signature can be used as an Struts 2 Action object.
Threading ModelStruts 1 Actions are singletons and must be thread-safe since there will only be one instance of a class to handle all requests for that Action. The singleton strategy places restrictions on what can be done with Struts 1 Actions and requires extra care to develop. Action resources must be thread-safe or synchronized.Struts 2 Action objects are instantiated for each request, so there are no thread-safety issues. (In practice, servlet containers generate many throw-away objects per request, and one more object does not impose a performance penalty or impact garbage collection.)
Servlet DependencyStruts 1 Actions have dependencies on the servlet API since the HttpServletRequest and HttpServletResponse is passed to the executemethod when an Action is invoked.Struts 2 Actions are not coupled to a container. Most often the servlet contexts are represented as simple Maps, allowing Actions to be tested in isolation. Struts 2 Actions can still access the original request and response, if required. However, other architectural elements reduce or eliminate the need to access the HttpServetRequest or HttpServletResponse directly.
TestabilityA major hurdle to testing Struts 1 Actions is that theexecute method exposes the Servlet API. A third-party extension, Struts TestCase, offers a set of mock object for Struts 1.Struts 2 Actions can be tested by instantiating the Action, setting properties, and invoking methods. Dependency Injection support also makes testing simpler.
Harvesting InputStruts 1 uses an ActionForm object to capture input. Like Actions, all ActionForms must extend a base class. Since  other JavaBeans cannot be used as ActionForms, developers often create redundant classes to capture input. DynaBeans can used as an alternative to creating conventional ActionForm classes, but, here too, developers may be redescribing existing JavaBeans.Struts 2 uses Action properties as input properties, eliminating the need for a second input object. Input properties may be rich object types which may have their own properties. The Action properties can be accessed from the web page via the taglibs. Struts 2 also supports the ActionForm pattern, as well as POJO form objects and POJO Actions. Rich object types, including business or domain objects, can be used as input/output objects. The ModelDriven feature simplifies taglb references to POJO input objects.
Expression LanguageStruts 1 integrates with JSTL, so it uses the JSTL EL. The EL has basic object graph traversal, but relatively weak collection and indexed property support.Struts 2 can use JSTL, but the framework also supports a more powerful and flexible expression language called "Object Graph Notation Language" (OGNL).
Binding values into viewsStruts 1 uses the standard JSP mechanism for binding objects into the page context for access.Struts 2 uses a "ValueStack" technology so that the taglibs can access values without coupling your view to the object type it is rendering. The ValueStack strategy allows reuse of views across a range of types which may have the same property name but different property types.
Type ConversionStruts 1 ActionForm properties are usually all Strings. Struts 1 uses Commons-Beanutils for type conversion. Converters are per-class, and not configurable per instance.Struts 2 uses OGNL for type conversion. The framework includes converters for basic and common object types and primitives.
ValidationStruts 1 supports manual validation via a validatemethod on the ActionForm, or through an extension to the Commons Validator. Classes can have different validation contexts for the same class, but cannot chain to validations on sub-objects.Struts 2 supports manual validation via the validate method and the XWork Validation framework. The Xwork Validation Framework supports chaining validation into sub-properties using the validations defined for the properties class type and the validation context.
Control Of Action ExecutionStruts 1 supports separate Request Processors (lifecycles) for each module, but all the Actions in the module must share the same lifecycle.Struts 2 supports creating different lifecycles on a per Action basis via Interceptor Stacks. Custom stacks can be created and used with different Actions, as needed.

Friday, March 16, 2012

configure glassfish in myeclipse

What is the need to Override Hashcode() and equals() method

Although there are lots of materials are available on internet and API document about the necessity of the overriding the hashcode() and equals() method in Java but lots of new developers still not able to understand the necessity of hashcode() method.
In this article, I will try to explain step by step the need of overriding hashcode() method in Java.
Few Thump rules:
  • If two objects are same then they must return same value in hashcode() and equals() method whenever invoked.
  • It is not necessary that two different object must have different hashcode values. it might be possible that they share common hash bucket.
JVM assigns unique hashcode value to each object when they are created in memory and if developers don’t override the hashcode method then there is no way the two object returns same hashcode value.
As the question comes in your mind that equals() method is used to compare objects that they are having same value or not but why should we override the hashcode method ?
The answer to the question is for the hash technique based data structures like HashMap and HashTable.
How Hashcode works in java
How Hashcode works in java
As you can see in above diagram that every object is placed in Hash bucket depending on the hashcode they have. It is not necessary that every different object must have different hashcode. hashcode is used to narrow the search result. When we try to insert any key in HashMap first it checks whether any other object present with same hashcode and if yes then it checks for the equals() method. If two objects are same then HashMap will not add that key instead it will replace the old value by new one.
What will happen if I don’t override the hashcode method?
Ans : If the object does not implement hashcode() method and used as key then we will not get the object back as shown in below code.

Add sharing buttons in web page

Code for Sharing buttons:

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style addthis_32x32_style">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
<script type="text/javascript" src=""></script>
<!-- AddThis Button END -->


Thursday, March 1, 2012

Top 20 Java Websites

Here’s the best 20 Java websites in my collections, which provides latest Java news, articles and tutorials. If you have other great Java websites, please leave a comment to share with others.
P.S The order doesn’t means any priority.

1. O’Reilly Java
Since : 10-feb-2000
Rss :
Description : O’Reilly’s, contains latest Java technology news, quality code snippets, full example and detail explanation.

2. Sun Developer Network (SDN)
Since : 19-mar-1986
Rss :
Description : The official Java developer website, always get the latest Java related news here.

Since : 21-dec-1995
Rss :
Description : Java news and articles in

Since : 18-jun-1997
Rss : None
Description : The Java community website hosted by Oracle.

5. IBM’s Developerworks
Since : 19-mar-1986
Rss :
Description : Java news and articles in IBM’s Developerworks.

6. Java World
Since : 22-nov-1995
Rss :
Description : Well-known Java websites, you just can’t miss this one.

7. Devx
Since : 26-sep-1997
Rss :
Description : Java news and articles in

Since : 05-jan-2000
Rss :
Description : Java community to discuss the server side development.

9. Big Moose Saloon
Since : 27-aug-2004
Rss : Vary in topic, visit
Description : Friendly and popular Java forum.

10. Stack Overflow
Since : 26-dec-2003
Rss :
Description : Well-known generic programming Q & A site organized by tags. Java topics included.

11. jGuru
Since : 16-sep-1997
Rss : None
Description : Java articles and Q&A style forum.

12. Official Java Tutorials

official java tutorials
Since : Unknown
Rss : None
Description : The Official Java tutorials from Oracle.

13. Java Blogs Aggregator
Since : 25-nov-2002
Rss :
Description : Blogs aggregator for many active Java-based blogs.

14. Java-Source.Net
Since : 25-feb-2004
Rss : None
Description : Java frameworks collection site. Well organized.

15. Java Lobby

Since : 17-may-1998
Rss :
Description : The heart of the Java developer community.

16. Jdocs
Since : 01-jul-2004
Rss : None
Description : Search engine for Java API documentation.

Since : 07-nov-2004
Rss : None
Description : Many Java programming tutorials and source code example, well organized by categories.

18. Java Tips
Since : 22-Apr-2005
Rss : None
Description : Many quick and Java source code example.

19. RoseIndia
Since : 23-may-2000
Rss : None
Description : Collection of Java tutorials, cover wide range of Java topics.

20. Mkyong
Since : 30-oct-2007
Rss :
Description : Cover wide range of the Java tutorials : Spring, Hibernate, Struts, Struts 2…