Four common frameworks for Java EE development and four major javaee frameworks

Source: Internet
Author: User

Four common frameworks for Java EE development and four major javaee frameworks

We have made many introductions to the Java EE Framework. This article will give a systematic summary of the four frameworks commonly used in Java EE.

 

Struts

Struts is an MVC framework based on the Sun Java EE platform, mainly implemented using Servlet and JSP technologies.

 

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

 

1. Model is essentially an Action class in Struts (This will be discussed in detail later). developers can implement business logic through it, at the same time, the user request to the Action through the Controller forwarding process is based on the configuration information described by the struts-config.xml file.

 

2. View is a complete set of JSP custom tag libraries that work with the Controller Servlet. using them, we can quickly create an application system interface.

 

3. The Controller is essentially a Servlet that forwards client requests to the corresponding Action class.

 

4. A bunch of sdks used for parsing XML files. Struts uses XML to describe how to automatically generate some JavaBean attributes, in addition, Struts also uses XML to describe the user prompt information in international applications (This achieves the 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. Spring's goal is to implement a comprehensive integration framework, implement a combination of multiple child frameworks under the Spring framework. These child frameworks can be independent of each other, or they can be replaced by other framework schemes, spring hopes to provide a one-stop shop framework integration solution.

 

Spring will not specifically propose some sub-frameworks to compete with the existing OpenSource framework, unless it feels that the proposed framework has a better idea, for example, Spring has its own MVC framework scheme, because it thinks there are many improvements to the existing MVC solution, but it does not force you to use the solution it provides, you can choose the framework you want to replace its sub-framework, for example, you can still integrate your Struts framework in Spring.

 

The core concept of Spring is IoC, and the abstract concept of IoC is "dependency transfer". For example, "high-level modules should not depend on low-level modules, however, all modules must rely on abstraction. This is a manifestation of IoC. "implementation must depend on abstraction rather than abstract dependency implementation" is also a manifestation of IoC, "applications should not depend on containers, but containers serve Applications" is also a manifestation of IoC.

 

Advantages of Spring's adequacy:

 

Spring can effectively organize your intermediate layer objects, whether or not you choose to use EJB. If you only use Struts or other frameworks that contain Java EE-specific APIs, you will find that Spring is concerned with the issues left behind.

 

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 features of the system.

 

Spring can eliminate the need for custom files using various formats of attributes, and can be configured in a consistent way throughout the application and project. I was once confused that a specific class had to read Javadoc or even the source code to find the keyword or system attribute of a phantom attribute? With Spring, you can easily see the JavaBean attribute of the class. The use of inverted control (discussed below) helps with this simplification. Spring can promote good programming habits through interfaces rather than classes, reducing the programming cost to almost zero.

 

Spring is designed to minimize the reliance on its APIs for Applications created using it. Most business objects in Spring applications do not depend on Spring.

 

Applications built using Spring are easy to perform unit tests.

 

Spring makes the use of EJB an implementation choice, not an inevitable choice of application architecture. You can use POJOs or local EJBs to implement business interfaces without affecting the calling code.

 

Spring helps you solve many problems without using EJB. Spring can provide an EJB replacement, which is suitable for many web applications. For example, Spring can use AOP to provide declarative transactions instead of using EJB containers. If you only need to deal with a single database, you do not even need to implement JTA.

 

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

 

Spring does allow you to solve your problem through the simplest and most feasible solution. These features are of great value.

 

What can Spring do?

 

Spring provides many features, so I will quickly display all of its main aspects in turn.

 

Task Description:

 

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

 

Spring aims to make Java EE easy to use and promote programming habits.

 

Spring does not re-develop existing things. Therefore, in Spring, you will find packages without logging, no connection pools, and no distributed transaction scheduling. These are provided by open-source projects (such as Commons Logging for all log output, or Commons DBCP for data connection pools), or by your application server. For the same reason, we have not provided the O/R mapping layer. For this reason, there are good solutions such as Hibernate and JDO.

 

Spring aims to make existing technologies easier to use. For example, although we do not have the underlying transaction coordination processing, we provide an abstraction layer covering JTA or any other transaction policies.

 

Spring does not directly compete with other open-source projects unless we feel that we can provide new things. For example, many developers have never been happy with Struts and feel that there is still room for improvement in the MVC web framework. In some fields, such as lightweight IoC containers and AOP frameworks, Spring has direct competition, but there are no more popular solutions in these fields. (Spring is a pioneer in these areas .)

 

Spring also benefits from internal consistency.

 

All developers are singing the same song, and the basic idea is still the ones designed and developed by Expert One-on-One Java EE.

 

In addition, we have been able to use some major concepts, such as inverted control, to deal with multiple fields.

 

Spring can be transplanted between application servers.

 

Of course, ensuring portability is always a challenge, but we avoid any specific platform 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. It can help programmers inject dependencies between components to minimize dependencies between components and improve component reusability, spring is a low-invasive (invasive) framework, and components in Spring do not realize that they are in Spring, which allows components to be easily detached from the framework, components can be added to the framework in a simple way, making integration of components and even frameworks easy.

 

Another Aspect that Spring attaches the most importance to is support of AOP (Aspect-OrientedProgramming). However, the AOP framework is only a sub-framework supported by Spring. It is not an appropriate description that Spring framework is an AOP framework, people map the novelty of AOP to Spring, so that people's attention to Spring is concentrated on its AOP framework. Although there is some misunderstanding, but it also highlights another interesting feature of Spring.

 

Spring also provides the MVC Web framework solution, but you can also combine the MVC Web framework you are familiar with Spring, such as Struts and Webwork, can be integrated with Spring to become your own solution. Spring also provides integration in other aspects, such as the integration of persistent layers, such as JDBC, O/R Mapping tools (Hibernate, iBATIS), and transaction processing, spring is an all-round application framework.

 

Hibernate

 

Hibernate is an open-source object relationship ing framework that encapsulates lightweight JDBC objects so that Java programmers can use the object programming thinking to manipulate the database. Hibernate can replace CMP in the JavaEE architecture of the application EJB to achieve data persistence. It can also be used in any scenario where JDBC is used, either in Java client or in Servlet/JSP Web applications.

 

How Hibernate works

 

Hibernate does not impede you or force you to modify the behavior of objects. They do not need to implement any incredible interfaces to survive. The only thing that needs to be done is to create an XML "ing document" That tells Hibernate that you want to save classes in the database and how they are associated with tables and columns in the database, then it can be required to obtain data in the form of an object, or save the object as data. Compared with other solutions, it is almost perfect.

 

Since this article is only an introductory article, we will not introduce a specific example of building and using the Hibernate ing document (in Hibernate: an example is provided in the first chapters of A Developer's Notebook ). In addition, you can find some good examples in the online and Hibernate documents. For more information, see the "Other Information" section below. It is actually quite intuitive. Attributes in an application object are associated with the correct database structure in a simple and natural way.

 

During runtime, Hibernate reads the ing document and dynamically constructs Java classes to manage the conversion between the database and Java. In Hibernate, there is a simple and intuitive API used to query 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 modification. Similarly, it is easy to create new objects. You only need to create them in the conventional way and then tell Hibernate about them so that they can be saved in the database.

 

The Hibernate API is easy to learn, and its interaction with the Program Stream is quite natural. You can call it at an appropriate location to achieve your goal. It brings a lot of advantages in automation and code saving, so it is worthwhile to spend a little time learning it. In addition, you can also obtain another benefit, that is, the Code does not need to care about the type of database to be used (otherwise, you must even know ). My company has had the experience of being forced to change the database vendor in the later stages of the development process. This will cause a huge disaster. However, with Hibernate, you only need to modify the Hibernate configuration file.

 

The discussion here assumes that you have created a relational database by creating the Hibernate ing document and have the Java class to be mapped. There is a Hibernate "toolset" that can be used during compilation to support different workflows. For example, if you already have a Java class and ing document, Hibernate can create (or update) required database tables for you. Alternatively, Hibernate can also generate data classes only starting from the ing document. Alternatively, you can design your database and classes in reverse order to develop a ing document. There are also alpha plug-ins for Eclipse, which can provide intelligent editing support in IDE and graphic access to these tools.

 

Use Hibernate

Since Hibernate looks so flexible and easy to use, why other tools? The following are some scenarios that can help you make judgments (perhaps by providing some comparisons and context, you can help identify scenarios that are very suitable for Hibernate ).

 

If the application needs data storage very easily-for example, you only want to manage a group of users first-you do not need a database, not to mention a good object-link ing System (even if it is as easy to use as Hibernate )! From Java1.4, a standard Java Preferences API can play this role well.

 

For those who are familiar with relational databases and know how to execute perfect SQL queries to interact with enterprise databases, Hibernate seems to be a little out of the way, this is just like a speedboat with power and automatic gear will make performance-oriented racing drivers impatient. If you belong to this type of person, if your project team has a strong DBA, or you have some stored procedures to handle, you may want to study iBATIS. The creator of Hibernate regards iBATIS as another interesting choice. I am very interested in it, because we once developed a similar system for an e-commerce site (with more powerful functions), and since then, we have already used it in other environments, although we prefer Hibernate in new projects after we discover Hibernate. You can think that the SQL-centered solution (such as iBATIS) is a "reverse" Object/link ing tool, while Hibernate is a more traditional ORM.

 

Of course, there are other external reasons that may lead to another method. For example, in an enterprise environment, you must use a mature EJB architecture (or some other non-Common Object ing systems ). You can customize code for platforms that provide your own data storage tools, such as Mac OS X's CoreData. A storage specification such as an xml dtd does not involve relational databases at all.

 

However, if you are using a rich object model and want to save it flexibly, easily, and efficiently (whether or not you are about to start or have decided to use relational databases, as long as this is an option-and there are excellent free databases available, such as MySQL, or HSQLDB that can be embedded in Java, it should always be an option ), hibernate is probably your ideal choice. You may be surprised to save much time and enjoy it.

 

Swing

The graphic user interface (GUI) library was originally designed to allow programmers to build a common GUI so that it can be properly displayed on all platforms. However, it is a pity that AWT produces graphical user interfaces that are equally inadequate in the view of various systems. JAVA1.2 adds a Java basic class (JFC) to the old java1.0 AWT ), this is part of a GUI called "Swing. Swing is the second generation of GUI development tool set. AWT uses implementations related to specific platforms, but most Swing components are not. Swing is a collection of GUI components built on the upper layer of AWT. To ensure portability, it is fully written in Java. Compared with AWT, Swing provides more complete components, introduces many new features and capabilities. Swing provides more component libraries, such as JTable, JTree, and Jcombox. Swing also enhances the functions of Components in AWT. It is precisely because Swing has so many advantages that we will use Swing in future development. The JComponent class is the base class of the Swing component, and JComponent inherits from the Container class. Therefore, all Swing components are AWT containers. Swing adopts the MVC design mode.

 

For more information, see:Mingli.com

Friend needs to learn more, please add a ball :,

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.