"Reprint" Java ee Apocalypse

Source: Internet
Author: User
Tags object serialization

Objective

Recently this time has been learning Java EE, has just completed from 0 to 1 of the Metamorphosis, so by the way I understand the Java EE, to the new beginner to learn some clues, and the so-called "revelation", that is the meaning.

A. What is Java ee?

Java EE (Java Enterprise Edition) is a software architecture for enterprise applications and is an idea, a set of specifications.

Two. The history of Java EE

Java Enterprise Edition Development unconsciously has been 12 years, do not know that everyone has not noticed, a start, Java Enterprise Edition abbreviated as "Java EE", until version 5 was renamed as the "the", and now the latest version is Java EE 6.

Here, someone might ask, why are there so many sets of Java EE specifications? What are the differences between these versions?

The emergence of 1.j2ee1.2 is mainly the binding of the previous individual specifications together.

2.j2ee1.3, is to continue to improve the architecture of the Java EE.

3.j2ee1.4, the main topic is to add an important theme: Web Service

4. While Java EE 5, the theme is "simplification", simplifying the previously complex idea of the Java EE and improving the development experience.

Three. What is the problem that Java EE is going to solve?

What problem does 1.Java ee solve?

From the background of Java EE Development, it is closely related to "distributed Application" and "Internet Application", which is the problem that Java EE solves!

In fact, distributed applications with the 90 's rise of the internet gradually began to popularize. In the 90, a variety of distributed application standards were gradually born, such as: OMG's CORBA,MS DCOM, and Sun after the introduction of the Java RMI (Remote Method invocation), the RMI as a communication infrastructure to build Java EE. I think themost important problem for Java EE is "Distributed Application". And in the next competition, Java EE is not to be entrusted, gradually replaced the status of Corba,dcom.

2. Distributed Applications and RPC

RPC (Remote Procedure Call), when chatting to distributed applications, many people will think of it the first time. RPC is called a service remotely, but the effect is the same as a local call. At first, RPC was very similar to the C-language function call, but with the development of programming languages and technologies, especially the wide application of object-oriented and component-oriented technology, "remote object/Method Invocation" appeared. The so-called "remote object/Method call" actually hides the difference between invoking the remote object and the local object, allowing the caller to invoke the remote object as if it were a local object. In essence, the initial RPC and later "remote object/method calls" are slightly different, and in "remote object/Method invocation", the tuned service also needs to be considered such as: Object lifecycle management, transaction processing ... These problems. But generally speaking, the initial RPC and the "remote object/Method call" are all called RPC, so previously mentioned as: Dcom,corba,java RMI,. NET remoting is called RPC. And I think the essence of RPC is: Application protocol + transport protocol. The difference between the various RPC implementations is also here.

The so-called "distributed Application", in fact, can be said to use RPC, each distributed in different machine application modules into a system. It can be said that RPC is the basis of "distributed Application", so there is "RMI as the basis for communication infrastructure Java EE," said:>

Four. Java EE architecture

Here, I'm going to start with an analysis of "enterprise applications" and gradually build the entire Java EE system.

1. Overview Java EE architecture

To impress, let's take a look at the simplest Java EE frame composition:

As you can see, Java EE is generally divided into 4 tiers:

(1) Client

(2) Web tier

(3) Business Logic Layer

(4) Enterprise Information Layer (eis:enterprise information System)

Oh, do not think Java EE just describes the service-side specification, in fact, it contains some of the client-related things, such as: applets ... However, the focus of Java EE is on the server side, and this article focuses on the Java EE on the server side of the content.

2. "Enterprise Application" analysis

(1) Distributed applications

First of all, an "enterprise Application" represents, the system is certainly "very large", such a large system, so many applications, it is impossible to deploy the application on a machine, so the "distributed Application" the need to appear logically. In an ideal "enterprise Application", a variety of functional modules should be distributed on different machines, and we can invoke them dynamically when a function is needed.

(2) System layering

In enterprise applications, the functionality of the business can be very complex. At this point, decoupling between modules and the beginning of the hierarchy of the system is important, decoupling and layering will make the system structure clear, and robust. and the traditional layered mode is generally: Access layer, logic layer, data layer.

(3) asynchronous

When designing a distributed application, the first question you encounter is: Wait ... in an enterprise application, the processing of the business is complex. If the handle module is deployed to a different machine, it is likely to need to be called on multiple machines to process a business, and the operation of the submodule will take some time, and "Wait" appears. Since you cannot predict when this complex business will be processed, the concept of "async" is also logically introduced. (In fact, this also reflects the "speed separation" principle in software design)

(4) Business, security

There is not much to say about the importance of the business.

and security, generally refers to the authorization of a module, authentication and so on, in enterprise-class applications, security is absolutely an important piece.

(5) Integration of Java EE platform with other existing resources, services and systems

Before Java EE came out, many companies were likely to have built a more sophisticated enterprise information System (EIS), and it was clear that integration with these existing systems was particularly important in enterprise applications.

3.Java EE Architecture Details

OK, now let's step through the role of each part of Java EE.

(1) servlet,jsp

Jsp,servlet is a "web layer" and belongs to "Dynamic Web technology". The so-called "Dynamic Web Technology" and traditional "static web technology" is not the same, the traditional "static web technology" White is to make good HTML files directly uploaded to the server and directly for the customer to browse, and "Dynamic Web technology" is each time according to the user request, dynamically generate response page and return. The benefits of "Dynamic Web technology" are self-explanatory, from flexibility to data privacy ... and other aspects of the "static Web page" can not be comparable. But "Dynamic Web technology" is also flawed, is relatively slow, now the solution is generally: "Dynamic Web Pages" in the relatively fixed part of the cache, that is, the so-called "static page." (Amount ... ") Static pages "and" static pages "are no different in nature, are static pages, but there is a big difference in thinking. And now programmers generally give a new meaning to the word "static": "Cache")

"1" Servlet

A servlet is actually a Java class written in the servlet specification, and unlike a Java application that is started by a traditional command line, the servlet resides inside the Web server and is loaded and invoked by the Web server.

"2" JSP

The JSP full name is: JavaServer Page. The purpose of this technology is actually very simple, in order to compensate for the servlet a very important flaw: "Trouble."

Let's take a look at where the servlet is going to be troublesome, here's an example of a servlet handling get requests:

public  void Doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {System.
       
        out.println (
         "processing GET request ing ..."); Response.setcontenttype ( "text/html;charset=gb2312"); PrintWriter out = Response.getwriter (); out.println ( "<HTML>");//static content out.println ( "<BODY>"); Static content out.println ( "hyddd ' Servlet Demo" + New Date (). toString ()); Dynamic content out.println ( "</BODY>");//static content out.println ( span class= "str" > "</HTML>"); Static content}             
          

From the above example, I believe you have found the problem, the servlet is mainly to mix dynamic content into static content to produce HTML, which will result in the servlet code output a large number of HTML tags, wow, hell, is hell, at the same time, This is also very detrimental to the programmer and UI artwork (don't expect the artist to write HTML tags with you). In order to solve these problems, JSP was born.

JSP is a Dynamic Web page technology built on the servlet specification, usually by embedding JSP tags and script code in HTML pages. JSP separates the static content from the dynamic content, and realizes the separation of content and representation.

The relationship between "3" servlet and JSP

It is more clearly described that the JSP file is first converted to a servlet class, then compiled, and the servlet instance is started to respond to client requests. Why JSP is a Dynamic Web page technology built on a servlet can be seen here.

The web layer is mainly JSP and Sevlet two technologies.

(2) EJB (Enterprise JavaBean)

As I said before, distributed applications are a basic requirement of Java EE, the amount ... What is the "distributed" application on different machines in what form? The answer is: EJB. EJB belongs to the business logic layer.

The so-called Bean is actually the "component" meaning. EJB allows you to assemble different applications into large applications with local/distributed calls, like building blocks, so that you can focus on the business logic of your business, while the underlying services such as transactions, networks, security, and so on, are left to the EJB server developers to solve.

With component-based development, code reuse can be raised to a new height. With object-oriented development, the reuse of classes is based on components, and reuse is a larger block of functionality.

"1" EJB vs Java Bean

I personally think that Java beans are equivalent to data storage classes (not involving specific business logic), are dedicated to storing data, provide getter,setter methods, and can be run directly on the JVM. EJBs are equivalent to a functional module that provides services for the business logic, while the runtime requires the help of the EJB container.

EJB is the most important technology in the business logic layer.

(3) Container (container)

The concept of container often appears in Java EE, the so-called container, in the Java EE 5 tutorial with such an explanation: "Containers is the interface between a Component and the low-level platform-specific functionality that supports the component. "And container the role I personally think is:" Application " Provide an environment that allows it to not have to focus on certain issues, such as: System environment variables, transactions, lifecycles ... in layman's words,container is like a "Secretary" that helps the "application" manage all sorts of messy problems and provides runtime support for them .

Of these, there are two very important containers in Java EE: theWeb container and the EJB container

"1" Web container

The Web container is the Java EE container for hosting "Web Applications" and is primarily responsible for managing "Servlet" and "JSP" runs.

"2" servlet container

In fact, the servlet in it refers to the servlet container. The servlet is designed to actually be a better thread container based on the threads pool, see:

"3" EJB container

The EJB container is primarily responsible for managing the operation of the EJB.

While EJB design is actually based on the idea of object pooling, you can think of ejb= object pool + remote object pool. See:

"4" servlet and EJB

In fact, based on the design of the servlet and EJB, we can already see the Java EE definition of the roles. The nature of the thread determines that the servlet is only suitable for some simple lightweight applications; Once the problem is complicated, the best thing is to use EJBS.

(4) RMI

RMI Full Name: Java Remote method Invocation, is the use of Java object Serialization mechanism, the realization of the remote class object instantiation and the method of invocation.

RMI is primarily responsible for solving communication problems in Java EE, especially for communication between different EJB containers. As you know, in distributed applications, the communication between each function module (EJB) needs to have a unified RPC protocol, otherwise it cannot communicate, and RMI is responsible for this work.

"1" RMI and Corb

It can be said that RMI is the Java version of CORBA implementation.

"2" Talk about "remote call"

Now the main way of remote invocation, whether it is com/com+,soap,webservice,rmi,.net remoting, White is the same, is the serialization, network transmission, deserialization .

Serialization mode: The same runtime, can be native binary serialization , serialization of high efficiency. The way text is serialized (xml/json/custom format) can be cross-platform and language, generally based on intermediate types. However, this serialization method is inefficient and the amount of data is also too large.

Network transport: You can make socket/http or custom protocols. Socket data redundancy is minimal and most efficient. RMI is actually a custom protocol on the socket. HTTP to take the HTTP message, the text is the most appropriate way to achieve the simplest, development and deployment of convenience.

(5) JMS

Jms:java Message Service. JMS provides a message mechanism, primarily to provide support for asynchronous communication, and is an important base module for Java EE. It is important to note that asynchronous communication, which generally employs a messaging mechanism, is most common in Windows.

(6) JTA

Jta:java Transaction API, which mainly provides transactional services and distributed transaction management functions, ensures the consistency of distributed transactions and is an important basic module of Java EE.

(7) JAAS

Jaas:java Authentication Authorization Service (Java Certified to the Licensing Service) provides security for Java components, such as which servelt,jsp can be accessed by which users, which EJBS can be invoked, and so on. However, it is important to note that Jaas only provides protection for Java EE components, which is not available for enterprise application business permissions.

(8) Connector

The main function of connector is to integrate other existing resources, services and systems into the Java EE system. Different service providers and Java EE platforms define different protocols, and connector refers to the implementation of these protocols.

So far, the core modules of Java EE have been introduced, so let's look at the architecture diagram of the EE 1.3 (the Java EE architecture at that time is relatively simple):

4.J2EE 1.4 and Java EE 5 architecture

(1) Java EE 1.4 Architecture

The Java EE 1.4 has added an important theme: "Web Service", including: Jax-rpc,saaj,web Srvcs,jaxr belongs to this piece of stuff.

(2) Java EE 5 Architecture

about Java EE 5 Here is not detailed introduction:,, we are interested to refer to the Java EE Tutorial 5 ".

Postscript

This article wrote me 3 days, but also turned over N more information, I hope this article is really helpful for beginners, and this article contains a lot of personal views, if there are errors please point out:>

With regard to Java EE 5, I will continue to tidy up if there is time.

Important references

"1" The history of JAVA EE 5 "

"2" The Java programmer is working on something. "

"3" Java EE Tutorial 5 "

"4" What is the "Java ee"? 》

"Reprint" Java ee Apocalypse

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.