Four common frameworks for Java EE development

Source: Internet
Author: User
Tags object model

We have a lot of introduction to the framework of Java EE, this article will be used in Java EE Four framework to do a systematic induction, I hope you like.

Struts

Struts is an MVC framework based on the Sun Java EE platform, implemented mainly by servlet and JSP technology.

The struts framework can be divided into the following four main sections, three of which are closely related to the MVC pattern:

1, model, essentially in struts, the model is an action class (this will be discussed in detail later), through which the developer implements the business logic, while the user requests through the controller The forwarding process to the action is based on the configuration information described by the Struts-config.xml file.

2. Views, view, is composed of a set of JSP custom tag libraries that work with the controller servlet, which allows us to quickly build the interface of the application system.

3, controller, is essentially a servlet that forwards the client request to the appropriate action class.

4. A bunch of toolkits for XML file parsing, struts uses XML to describe how to automatically generate some JavaBean properties, and struts uses XML to describe user-prompted information in internationalized applications (which enables multi-language support of the application system).

Spring

Spring is a lightweight Java EE application framework.

The core of spring is a lightweight container (Container) that implements the IOC (inversion of Control) mode container, and the goal of spring is to implement a full-fledged integration framework that implements a combination of multiple sub-frameworks in the spring framework, These sub-frameworks can be independent of each other, or can be replaced with other framework schemes, and Spring wants to provide a framework consolidation solution for One-stop shop.

Spring does not particularly propose sub-frameworks to compete with the existing opensource framework, unless it feels that the proposed framework is new enough, such as spring has its own MVC framework scheme, because it feels that there are many improvements to the existing MVC scheme, But it does not force you to use the scenario it provides, and you can choose the framework you want to replace its sub-framework, such as you can still integrate your struts framework in spring.

Spring's core concept is that IOC,IOC's abstract concept is "transfer of dependencies", such as "high-level modules should not rely on the lower modules, but the module must rely on abstraction" is a manifestation of the IOC, "implementation must rely on abstraction, rather than abstract dependency implementation" is also a manifestation of the IOC, " Applications should not be dependent on containers, but containers serving applications "is also a manifestation of the IOC.

The architectural benefits of spring:

Spring effectively organizes your middle-tier objects, whether or not you choose to use EJBS. If you just use struts or other frameworks that contain Java EE-specific APIs, you'll notice that spring is focused on the legacy.

Spring can eliminate the excessive use of singleton in many projects. Based on my experience, this is a major problem, which reduces the testability and object-oriented nature of the system.

Spring eliminates the need to customize files with attributes in a variety of formats, and is configured in a consistent way throughout the application and engineering. Ever confused, a particular class looking for a psychedelic attribute keyword or system attribute, do you have to read Javadoc or even source code? With spring, you can easily see the JavaBean property of the class. The use of inverted controls (discussed below) helps to accomplish this simplification. Spring can promote good programming habits through interfaces rather than classes, reducing programming costs to almost zero.

Spring is designed so that applications created with it depend as little as possible on his APIs. Most business objects in a spring application are not dependent on spring.

Applications built using spring are easy to unit test.

Spring enables the use of EJBS to be an implementation choice, not an inevitable choice for application architectures. You can choose to use POJOs or local EJBS to implement the business interface without affecting the calling code.

Spring helps you solve many problems without using EJBS. Spring provides an alternative to EJBS that are suitable for many Web applications. For example, spring can use AOP to provide declarative transactions without using an EJB container, if you only need to deal with a single database, and you don't even need a JTA implementation.

Spring provides a consistent framework for data access, whether using JDBC or O/R mapping products such as hibernate.

Spring does enable you to solve your problem with the simplest possible solution. These features are of great value.

What can spring do?

Spring provides a number of features, where I'll quickly show each of its main areas in turn.

Task Description:

First, let's clarify the spring range. Although spring covers many aspects, we already have a clear concept of what it should involve and what should not be involved.

The main purpose of spring is to make Java EE easy to use and promote good programming habits.

Spring does not re-develop what is already there. Therefore, in spring you will find a packet without logging, no connection pool, and no distributed transaction scheduling. These are available in open source projects (for example Commons Logging is used to do all the log output, or Commons dbcp used as a data connection pool) or provided by your application server. For the same reason, we did not provide the O/R mapping layer, there are good solutions such as Hibernate and JDO.

Spring's goal is to make existing technologies easier to use. For example, although we do not reconcile the underlying transaction, we provide an abstraction layer that overrides JTA or any other transaction policy.

Spring does not compete directly with other open source projects unless we feel that we can offer something new. For example, like many developers, we have never been happy with struts and feel that there is room for improvement in the MVC Web framework. In some areas, such as the lightweight IOC container and the AOP framework, Spring has direct competition, but there are no already popular solutions in these areas. (Spring is a pioneer in these areas.) )

Spring also benefits from intrinsic consistency.

All the developers are singing the same hymn, the basic idea is still the expert one-on-one Java EE design and development of those.

And we have been able to use some of the main concepts, such as inverted control, to handle multiple areas.

Spring is portable between application servers.

Of course, portability is always a challenge, but we avoid any particular platform or non-standardization, and support users on Weblogic,tomcat,resin,jboss,websphere and other application servers.

The core of spring is a Ioc/di container that helps program designers complete dependency injection between components, minimizing dependencies between components, and increasing reuse of components, and spring is a low-intrusive (invasive) framework. The components in spring do not realize that it is in spring, which allows components to be easily detached from the framework without any modification, and conversely, components can be added to the framework in a simple way, making it easy to integrate components and even frameworks.

Spring's most important aspect is support for AOP (aspect-orientedprogramming), but the AOP framework is just a sub-framework supported by spring, saying that the spring framework is an AOP framework that is not an appropriate description, and that people The emphasis on the AOP focus on spring, which focuses on its AOP framework, is somewhat misleading, but it also highlights another interesting feature of spring.

Spring also provides solutions to the MVC Web framework, but you can also integrate your familiar MVC Web framework with spring, such as struts, webwork, and so on, all of which can be integrated with spring into your own solution. Spring also provides other aspects of integration, such as the integration of persistent layers such as JDBC, O/R mapping Tools (Hibernate, IBATIS), transaction processing, and so on, and spring is a full-fledged application framework for the multi-faceted integration effort.

Hibernate

Hibernate is an open-source object-relational mapping framework that provides a lightweight object encapsulation of JDBC, allowing Java programmers to manipulate databases using object-programming thinking. Hibernate can be used to replace CMP in the Java EE architecture of the application EJB to complete data persistence. It can also be applied to any application using JDBC, either in Java client applications or in servlet/jsp Web applications

How Hibernate works

Hibernate does not interfere with you, nor does it force you to modify the way objects behave. They do not need to implement any magical interfaces to be able to persist. The only thing you need to do is create an XML "map document" that tells hibernate the classes you want to be able to save in the database, and how they relate to the tables and columns in that database, and then you can either ask it to get the data as an object, or save the object as data. It's almost perfect compared to other solutions.

Because this article is just an introductory article, there are no specific examples of building and using Hibernate mapping documents (I've covered an example in the first few chapters of Hibernate:a Developer's Notebook). In addition, some good examples can be found in online and hibernate documentation, see the "Additional Information" section below. It's actually quite intuitive. The properties in the Application object are associated with the correct database structure in a simple and natural way.

At run time, hibernate reads the mapping document and then dynamically constructs the Java class to manage the transformation between the database and Java. In Hibernate, there is a simple and intuitive API for executing queries against the objects represented by the database. To modify these objects, you only need to interact with them in the program, and then tell Hibernate to save the changes. Similarly, it's easy to create new objects by simply creating them in the usual way and then telling hibernate about them so that they can be saved in the database.

The Hibernate API is simple to learn, and its interaction with program flow is quite natural. It can be achieved by invoking it at the appropriate location. It brings a lot of automation and code savings benefits, so it's worthwhile to spend a little time learning it. There is another benefit, too, that the code doesn't care about the kind of database you want to use (or even need to know). My company has experienced the forced replacement of database vendors late in the development process. This can be a huge disaster, but with hibernate, you simply need to modify the hibernate configuration file.

The discussion here assumes that you have created a relational database by creating a Hibernate mapping document, and that you have a Java class to map. There is a hibernate "toolset" that can be used at compile time to support different workflows. For example, if you already have a Java class and a mapping document, hibernate can create (or update) the required database tables for you. Alternatively, hibernate can generate data classes just starting with the mapping document. Or, it can reverse-engineer your database and class to develop a mapping document. There are also alpha plug-ins for Eclipse, which provide intelligent editing support and graphical access to these tools in the IDE.

Where to use Hibernate

Since hibernate looks so flexible and useful, why use other tools? Here are some scenarios that can help you make judgments (perhaps by providing some comparison and context that can help you identify situations that are very suitable for hibernate).

If the application is very simple for data storage-for example, you just want to manage a set of user preferences-you don't need a database at all, let alone a good object-relational mapping system (even if it's as easy to use as Hibernate)! Starting with Java1.4, there is a standard Java The Preferences API is a good way to play this role.

For those familiar with using relational databases and understanding how to perform perfect SQL queries with enterprise database interactions, hibernate seems to be in the way, just as a speedboat with power and automatic gears can make performance-conscious racing drivers impatient. If you belong to this kind of person, if your project team has a strong DBA, or there are some stored procedures to handle, you might want to study ibatis. The creator of Hibernate itself treats Ibatis as another interesting option. I am interested in it because we have developed a similar system for an e-commerce site (which is more powerful), and since then, we have used it in other environments, although we usually prefer hibernate in new projects after we discover hibernate. You can argue that a SQL-centric solution (such as Ibatis) is a "reverse" object/Relationship mapping tool, and Hibernate is a more traditional ORM.

Of course, there are other external causes that can lead to another approach. For example, in an enterprise environment, you must use a mature EJB schema (or some other non-trivial object mapping system). You can customize the code for the platform that provides your own data storage tools, such as Mac OS X's coredata. It is possible to use a storage specification such as an XML DTD that does not involve a relational database at all.

However, if you are using a rich object model and want to save it flexibly, easily, and efficiently (whether you are starting or deciding to use a relational database, as long as this is a choice-and there are good free databases available, such as MySQL, or hsqldb that can be embedded in Java, It should always be a choice), then hibernate is probably your ideal choice. You may be amazed at how much time is saved, and how much you will like to use it.

Swing

The graphical user interface (GUI) library was originally designed to allow programmers to build a common GUI so that they could be displayed properly on all platforms. However, it is regrettable that the AWT produces a graphical user interface that is equally poor in every system, and JAVA1.2 adds the Java base class (JFC) to the old java1.0 AWT, which is part of a GUI called "Swing". Swing is the second generation of GUI development toolset, and AWT uses a specific platform-related implementation, while most swing components are not. Swing is a set of GUI components built on the upper level of AWT to ensure portability and is written in the Java language, and swing provides more complete components than AWT, introducing many new features and capabilities. Swing provides more library of components, such as: Jtable,jtree,jcombox. Swing also enhances the functionality of the components in AWT. It is because swing has so many advantages that we later use swing in development. The JComponent class is the base class for swing components, and jcomponent inherits from the container class, so all swing components are containers for AWT. Swing uses the MVC design pattern.

Four common frameworks for Java EE development

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.