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

Struts

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

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

1. Model, which is essentially an Action class in Struts (more on this later) that developers use to implement business logic, Meanwhile, the forwarding of user requests to actions via controllers is based on configuration information described in the Struts-config.xml file.

2, View (View), View is composed of a set of JSP custom tag library with controller Servlet work, using them we can quickly establish the interface of the application system.

3. A Controller, essentially a Servlet, forwards client requests to the corresponding Action class.

Struts uses XML to describe how to automatically generate JavaBean attributes. Struts also uses XML to describe user prompts in internationalized applications (thus achieving multilingual support for the application system).

spring

Spring is a lightweight Java EE application framework.

The core of Spring is a lightweight Container that implements the IoC(IoC of Control) model. The goal of Spring is to achieve a comprehensive integrated framework that combines multiple sub-frameworks within the Spring framework, which can be independent of each other. You can use other framework solutions instead, and Spring wants to provide a framework integration solution for one-stop Shop.

Spring doesn’t specifically come up with a subframework to compete with the existing OpenSource framework unless it feels that the proposed framework is good and new. For example, Spring has its own MVC framework because it feels that the existing MVC framework can be improved, but it doesn’t force you to use it. You can choose the framework you want in place of its children; for example, you can still integrate your Struts framework in Spring.

Spring’s core concept is the IoC, the IoC’s abstract concepts is the transfer of “dependency”, like “high-level modules should not depend on low-level modules, but the module must depend on the abstract” is a sign of the IoC, “implementation must rely on abstraction, rather than abstract depend on implementation” is also a manifestation of the IoC, the application should not depend on the container, It’s the container serving the application.”

Spring’s architectural benefits:

Spring organizes your middle-tier objects efficiently, whether you choose to use EJBs or not. If you only use Struts or another framework that includes Java EE-specific APIs, you will find that Spring addresses the remaining issues.

Spring can eliminate excessive use of Singleton on many projects. In my experience, this is a major problem that reduces the testability and object-oriented nature of the system.

Spring eliminates the need to customize properties files in a wide variety of formats, enabling a consistent approach to configuration throughout your application and project. Ever wondered if a particular class had to read Javadoc or even source code to find psychedelic property keywords or system properties? With Spring, you can easily see the JavaBean properties of a class. The use of inversion controls (discussed below) helps accomplish this simplification. Spring promotes good programming habits through interfaces rather than classes, reducing the cost of programming to almost nothing.

Spring is designed to make applications created using it as little dependent as possible on its APIs. Most business objects in Spring applications do not depend on Spring.

Applications built using Spring are easy to unit test.

Spring can make the use of EJBs an implementation choice, rather than an application architecture imperative. You can choose to implement the business interface using POJOs or Local EJBs without affecting the calling code.

Spring helps you solve many problems without using EJBs. Spring can provide an alternative to EJBs that are suitable for many Web applications. For example, Spring can use AOP to provide declarative transactions without using the EJB container, if you only need to deal with a single database, or even 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 problems with the simplest possible solution. These features are of great value.

What can Spring do?

Spring provides a lot of functionality, and I’ll quickly show you the main aspects in turn.

Mission Description:

First, let’s clarify the Spring scope. Although Spring covers a lot of ground, we already have a clear idea of what it should cover and what it shouldn’t.

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

Spring does not redevelop what is already there. Therefore, in Spring you will find no logging packages, no connection pooling, and no distributed transaction scheduling. These are provided by open source projects (such as Commons Logging for all Logging, or Commons DBCP for data connection pooling), or by your application server. For the same reason we didn’t provide an O/R mapping layer, there are good solutions like Hibernate and JDO.

Spring’s goal is to make existing technologies easier to use. For example, although we have no underlying transaction coordination, we provide an abstraction layer that overlays JTA or any other transaction strategy.

Spring does not directly compete with other open source projects unless we feel we have something new to offer. For example, like many developers, we were never happy with Struts and felt there was room for improvement in the MVC Web Framework. In some areas, such as lightweight IoC containers and AOP frameworks, Spring competes directly, but there are no already popular solutions in these areas. (Spring is a trailblazer in these areas.)

Spring also benefits from internal consistency.

All developers are singing the same praises, and the basic ideas are still those of Expert one-on-One Java EE design and development.

And we’ve been able to use some major concepts, such as inversion control, to deal with multiple domains.

Spring is portable across application servers.

Of course, ensuring portability is always a challenge, but we avoid any platform-specific or non-standardization and support users on WebLogic, Tomcat, Resin, JBoss, WebSphere, and other application servers.

The core of Spring is an IoC/DI container, which can help programmers to complete the dependency injection between components, so that the dependency between components can be minimized, and then improve the reuse of components. Spring is a low-invasive framework. Components in Spring are not even aware that they are in Spring, which allows components to be easily removed from the framework with little modification. Conversely, components can simply be added to the framework, making it easy to integrate components and even frameworks.

The other Aspect of Spring that gets the most attention is its support for AOP(aspect-oriented Programming). However, AOP framework is only a subframework of Spring’s support, and to say that the Spring framework is an AOP framework is not an appropriate description. The mapping of the newfangled AOP focus to Spring has focused attention on its AOP framework, which, while misleading, highlights another interesting feature of Spring.

Spring also provides MVC Web framework solutions, but you can also integrate familiar MVC Web frameworks like Struts, Webwork, and so on into your own solutions. Spring also provides other aspects of integration, such as persistence layer integration such as JDBC, O/R Mapping tool (Hibernate, iBATIS), transaction processing, etc. Spring has made efforts to integrate many aspects, so Spring is a comprehensive application framework.

Hibernate

Hibernate is an open source object-relational mapping framework, which provides lightweight object encapsulation for JDBC, enabling Java programmers to manipulate databases with object-programming thinking. Hibernate can replace CMP in the JavaEE architecture that applies EJB for data persistence. It can also be used anywhere using JDBC, either in Java client applications or in Servlet/JSP Web applications

How Hibernate works

Hibernate doesn’t hinder you or force you to change the way your objects behave. They don’t need to implement any magical interfaces in order to survive. All you need to do is create an XML “mapping document” that tells Hibernate the classes you want to keep in the database and how they relate to the tables and columns in the database, and then you can ask it to fetch the data as objects or save the objects as data. Compared to other solutions, it’s almost perfect.

Since this article is only an introductory article, I won’t introduce concrete examples of building and using Hibernate mapping documents (I did an example in the first few chapters of Hibernate: A Developer’s Notebook). In addition, some good examples can be found on the web and in Hibernate’s online documentation, see the “Additional Information” section below. It’s actually pretty straightforward. Properties in application objects are associated with the correct database structure in a simple and natural way.

At runtime, Hibernate reads the mapping document and then dynamically builds Java classes to manage the transformation between the database and Java. Hibernate has a simple and intuitive API for executing queries against objects represented by the database. To modify these objects, you (typically) just interact with them in your program and tell Hibernate to save the changes. Similarly, creating new objects is easy; Just create them in the normal way and tell Hibernate about them so you can save them in the database.

The Hibernate API is simple to learn, and its interaction with program flows is fairly natural. Call it in the right place, and you’ll do the trick. It brings a lot of benefits in terms of automation and code savings, so it’s worth spending a little time learning it. Another benefit is that the code doesn’t have to care what kind of database it is using (or it would even have to know). My company has had to change database vendors late in the development process. This can be disastrous, but with Hibernate, you can simply modify the Hibernate configuration file.

The discussion here assumes that you have built a relational database by creating Hibernate mapping documents and have Java classes to map. There is a Hibernate “toolset” available at compile time to support different workflows. For example, if you already have Java classes and mapping documents, Hibernate can create (or update) the necessary database tables for you. Alternatively, Hibernate can generate data classes just from mapping documents. Alternatively, it can reverse-engineer your database and classes to sketch out mapping documents. There are also alpha plug-ins for Eclipse that provide intelligent editing support in the IDE as well as graphical access to these tools.

Where to use Hibernate

Why use other tools when Hibernate seems so flexible and easy to use? Here are some scenarios to help you decide (perhaps by providing some comparisons and context, you can help identify situations where Hibernate is a good fit).

If your application’s data storage needs are simple — for example, if 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 Preferences API that serves this purpose well.

For someone familiar with relational databases and who knows how to execute perfect SQL queries to interact with enterprise databases, Hibernate can seem a bit of an obstacle, much like a speedboat with power and automatic gear can annoy a performance-conscious racing driver. If you’re one of those people, if you’re on a project team with a powerful DBA, or if you have some stored procedures to work with, you might want to take a look at iBATIS. Hibernate’s creators themselves see iBATIS as an interesting alternative. I was interested in it because we developed a similar system (with more power) for an e-commerce site, and we have used it in other environments since then, although we generally prefer to use Hibernate for new projects after discovering it. You can think of SQL-centric solutions (such as iBATIS) as “reverse” object/relational mapping tools, while Hibernate is a more traditional ORM.

Of course, there are other external reasons for taking a different approach. For example, in an enterprise environment, you must use a mature EJB architecture (or some other non-ordinary object mapping system). Code can be tailored to platforms that provide their own data storage tools, such as Mac OS X’s CoreData. You might use a storage specification like an XML DTD that doesn’t involve relational databases at all.

However, if you are using a rich object model, and want to be flexible, easily and efficiently save it (no matter whether you are started or have decided to use a relational database, as long as it is a good choice – and there are available free databases, such as MySQL, or can be embedded in the Java HSQLDB, it should be is always a choice). Hibernate is probably your ideal choice. You might be surprised at how much time you save and how much you’ll enjoy using it.

Swing

The graphical User interface (GUI) library was originally designed to allow programmers to build a generic GUI that would display normally on all platforms. Unfortunately, AWT produces graphical user interfaces that are equally bad from the point of view of all systems. Java 1.2 adds Java Foundation Classes (JFC) to the older Java 1.0 AWT, which is part of a GUI called “Swing.” Swing is a second-generation GUI development toolset, and AWT uses platform-specific implementations, while most Swing components do not. Swing is a collection of GUI components built on top of AWT. To ensure portability, it is written entirely in the Java language. Compared with AWT, Swing provides a more complete set of components, introducing many new features and capabilities. Swing provides more component libraries, such as JTable, JTree, and Jcombox. Swing also enhances the functionality of components in AWT. It’s because Swing has so many advantages that we’re going to use Swing in our development. The JComponent class is the base class for Swing components, and JComponent inherits from the Container class, so all Swing components are AWT containers. Swing adopts the MVC design pattern.