The core technology composition of the Java EE

Source: Internet
Author: User
Tags set cookie

The core technology composition of the Java EE

The cornerstone of EJB-J2EE
Corba-orb is its core
Rmi
Jsp
Java Servlet
JavaBean
Jdbc
Jms
Jta

EJB Overview

EJB model Features
Create and manage EJBs at run time by an EJB container
Customizing how EJBs are run when they are deployed
Client-side access coordinated by EJB container and server
Can be deployed to any compatible EJB container
The client view of the EJB is determined by the bean developer
EJB Specification Content
Server
Container
Classes and instances
Home and Remote interface
Client

The EJB's operating environment, which provides the interfaces defined in the specification, enabling the EJB class to access the required services
Container vendors can also provide additional service interfaces in containers or servers

EJB Server

Used to connect the client layer to the Resource management layer
Provides system services, such as security and transactions
There is a standard container that supports entity beans and session beans
Services for EJB Management and configuration
Tools for configuring EJBS
Security services
Workload Management Services
Persistent service out-of-the-name service
Transaction Processing Services

Session Bean

Stateful Bean
A short object that represents the client's interaction with the system and is deleted after the operation is completed
Each user has a session bean
No State bean
Do not maintain status information between customer requests
All instances of stateless session beans are the same (stateless session bean can support multiple clients)

Entity Bean

A component that encapsulates the implementation of a business entity or business process
is a persistent data component that represents a persistent (persistence) object stored on an external medium or an existing enterprise application resource
Entity Bean methods can take advantage of CMP (container-managed persistence) or BMP (bean-managed persistence) to obtain state in the resource manager
Shared access
Can be shared by multiple clients
Each instance of an entity bean has a unique object identifier
This unique identifier is the primary key that allows the client to find the corresponding entity bean instance
As with tables in a relational database, there are relationships between entity beans
In a school registration system, the STUDENTEJB of the student and the COURSEEJB of the course are related to the student's need to register for class.

EJB's customer-View API

EJB Local Interface
Defines some methods for client create, remove, and find EJB objects to use
EJB Remote Interface
Defines the business method of the EJB, all the business methods of the EJB must be defined in the remote interface to be accessed by the client
EJB class
Implementing business methods defined in the EJB remote interface
Ejb-jar.xml
Contains configuration information for EJB components

EJB class
Java classes, methods for implementing business methods and the life cycle of enterprise bean objects
EJB Client-View API: Comprised of the EJB's home interface and the EJB's remote interface
The home interface defines the Create,remove and find methods to control the life cycle of an EJB object
The remote interface defines the business methods that the customer can invoke on a particular EJB object

Deployment Descriptor
is an XML document that contains the declaration information about this EJB
EJB Name
Name of home and remote interface
EJB class Name
EJB type
EJB expects information about the service provided by the container, such as transaction processing
Environment Item for EJB

Simple EJB Example

First.java (Remote interface)

import java.rmi.RemoteException;import javax.ejb.EJBObject;publicinterface First extends EJBObject {  publicHerethrows RemoteException;  publicTherethrows RemoteException;}

Fisthome.java (Local interface)

import java.rmi.RemoteException;import javax.ejb.CreateException;import javax.ejb.EJBHome;publicinterface FirstHome extends EJBHome{  publiccreatethrows RemoteException, CreateException;}
Importjava.rmi.*;Importjavax.ejb.*; Public  class Firstbean implements Sessionbean { Public void ejbcreate() {} Public void Ejbremove()throwsRemoteException {} Public void ejbactivate()throwsRemoteException {} Public void ejbpassivate()throwsRemoteException {} Public void Setsessioncontext(Sessioncontext Sessioncontext)throwsremoteexception { This. Sessioncontext = Sessioncontext; } Public void  Here() {String strtarget = "I am here!";returnStrtarget; } Public void there() {String strsource = "you are there!";returnstrsource; }}

First Deployment Descriptor

<! DOCTYPE Ejb-jar Public '-//sun Microsystems, Inc.//dtd Enterprise JavaBeans 2.0//en ' http://java.sun.com/dtd/ejb-jar_2 _0.dtd ' ><Ejb-jar> <Enterprise-beans> <session><ejb-name>First</ejb-name><home>Com.javausr.example.FirstHome</Home><remote>Com.javausr.example.First</remote><ejb-class>Com.javausr.example.FirstBean</ejb-class><session-type>Stateless</session-type></session></Enterprise-beans> </Ejb-jar> 

Client Calls

public class MyStandAloneClient { public static void main(String[] args) { try { Context initial = new InitialContext(); //创建jndi初始化环境  Object objref = initial.lookup(“First"); //找到ejb的Remote Home Interface FirstHome home = (FirstHome)PortableRemoteObject.narrow(objref, FirstHome.class); First first = home.create(); //初始化ejb,得到Remote Interface first.here(); //调用商业方法sayHello() System.exit(0); } catch (Exception ex) { System.err.println("Caught an unexpected exception!"); ex.printStackTrace(); }}
CORBA Overview

Common Object Request Broker Architecture
is a distributed object architecture, independent of platform and language
In this architecture, an object can be accessed through method activation by a client or remote client on this computer
A customer (an object or an application) does not need to know the running environment of the called object (called the service object) or the programming language that implements the object
The customer only knows the logical address of the service object and the provided interface
The key to interoperability is IDL (Interface definition Language, Interface Definition language)
IDL description method in Object interface
These methods can be activated by other objects (or applications)

RMI Technology

Remote Method Invoke
is a lower-level protocol used by EJBS that invoke methods on remote objects and use serialization to pass data between client and server-side objects
Comparison with CORBA
The key difference is the language environment, Java RMI is a pure Java solution
CORBA does not define a security service, Java RMI inherits the security of Java
There are different implementations of CORBA
Matching on different platforms is difficult, and not all CORBA product developers support all platforms
But Java virtual machines are supported on almost all platforms, so Java RMI has higher portability
IIOP has provided the interoperability capabilities of Java RMI and CORBA, and the development of the two has been a trend of mutual reference.

JSP Technology

Mixing Java program code in the HTML language, interpreted by the server-side Java language engine
HTML is responsible for describing the information display format, JSP is responsible for describing the processing logic
JSP code execution requires JSP engines, such as Tomcat and Apache
Typical ways of JSP development
Direct use: Show simple dynamic effects
JSP + JavaBeans: Need to connect with database, manage information such as account
JSP + JavaBeans + Servlet: Separate transaction logic from presentation logic, JSP is responsible for the processing and output of the presentation logic, and the servlet focuses on the key business logic of the Web

How the JSP engine works

Translating a JSP page into a servlet (Java file)
The JSP engine calls the Java compiler to compile the servlet to get the executable class file
The JSP engine calls the Java Virtual machine to interpret the execution class file, generates an answer sent to the client, and then sends it to the customer
The above steps will not be executed until the JSP page is accessed for the first time, and will be more efficient later because the class file has been generated.

Comparison of JSP and ASP

Similarities
Are all running on the server, all belong to the Dynamic Web page generation technology
All use HTML to determine the layout of the page, to mix some code in the HTML code, to interpret the execution code by the language engine
HTML is responsible for describing the display style, the program code describes the processing logic
Difference
Based on Javaservlet and the entire Java EE system, JSP supports cross-platform
ASP is launched by Microsoft and can only be run on Windows platforms
The programming language under ASP is a scripting language such as VBScript, and the JSP uses Java
There is a more fundamental difference between ASP and JSP: The two language engines handle embedded program code in a completely different way in a page
Under ASP, VBScript code is interpreted by the ASP engine to perform
Under JSP, the code is compiled into a Servlet and executed by a Java virtual machine, which occurs only on the first request to the JSP page

Servlet overview

Servlets=server +applet
Java applet running on the Web server to extend Web server functionality
A technology that extends the functionality of the Web server and is written in Java, so it has access to the entire Java API library, including the JDBC API for accessing the enterprise database
Replaces other Web service Servlets programming patterns (such as CGI,ISAPI, etc.) with specific Java solutions, thus inheriting all Java features (cross-platform, multi-threading, OO)
The servlet APIs used to write servlets have no special requirements for server environments and protocols, so servlets is highly portable and does not have the performance limitations of other methods, such as CGI programs.
Servlets also uses the HTTP protocol to communicate with clients, so it is sometimes called sevlets "http Servlets"

The main object of the servlet

HttpServletRequest Object
About HTTP Requests
Request headers
Querying string query strings
Sessions Information Session
Cookies
HttpServletResponse Object
Used to format the HTTP response
Headers
Status Codes
Cookies

The life cycle of the servlet

Instantiation of
Web container to create a servlet instance
Initialization
The init () method of the container invocation instance
Service
If the container has a request to be routed to the servlet, the Service () method in the instance is invoked, the doget () or DoPost () method
Die
Call the Destroy () method to reclaim resources before the instance dies
Not available
Instance is deleted and marked for garbage collection

SERVLET BASIC Structure
Importjava.io.*;Importjavax.servlet.*;Importjavax.servlet.http.*; Public  class someservlet extends httpservlet {     Public void Doget(HttpServletRequest request, httpservletresponse response)throwsServletexception, IOException {//Use "request" to read and solicit information about (such as cookies)       //And form data      //Use "response" to specify HTTP answer status codes and answer headers      //(e.g. specify content type, set cookie)PrintWriter out = Response.getwriter ();//use "out" to send the reply to the browser}}
Comparison of Java servlet and JSP

Similarities
are based on Java technology, all of Java's features are inherited, and all Java APIs can be used
Work similar: JSP code is first converted to servlet code by the JSP container and then compiled into a class
Both have the same level of work in the Java EE Architecture and are responsible for connecting to the client
Difference
Different programming methods: Servlets are Java applets running on the Web server, and JSP is a script that is easier to write.
Application purposes: Servlets are primarily used to receive request information from the client, while the JSP is primarily responsible for transmitting server-side information to the client
JSP true Meaning: interface design and business logic design can be separated

JavaBean Overview

JavaBean is a Java-based component model, similar to Microsoft COM components
JavaBean through a Java virtual machine
The ability to extend the Java program infinitely, by combining the rapid generation of new applications
JavaBean's traditional application lies in the field of visualization, such as the application under AWT
Since the birth of JSP, JavaBean more application in the field of non-visualization, in the server-side application has shown a more and more strong vitality
JavaBean features that differ from Java classes
Constructors with public parameterless parameters
Each attribute must have a Set,get method
Implementing the Serializable interface

Property
The appearance and behavior characteristics that can be changed when you design the bean
The development tool publishes its properties by introspection the bean to learn its properties
Method
The method in JavaBean is the usual Java method, which can be invoked from other components or in a scripting environment.
By default, all of the bean's public methods can be called externally, but the bean generally only leads to a subset of its public methods
Event
The primary way for beans to communicate information to other components is to send and receive events

Methods of calling JavaBean by JSP
    <jsp:usebean>: Used to declare and instantiate the JavaBean class.<jsp:usebeanid="Object-name"scope="page | Request | Session | Application " type=" Type-of-object"class=" Fully-qualified-classname "  beanname="Fully-qualified-beanname"/>                     <jsp:setproperty>: The value used to design the JavaBean.<jsp:setpropertyname= "id-of-the-javabean"property =" Name-of-property "param=" Name-of-request-parameter-to-use "value=" New-value-of-this-property "/>                  <jsp:getproperty>: Used to get the value of a specific propoerty in JavaBean.<jsp:getpropertyname= "name-of-the-object"property =" Name-of-property "/>            
JDBC Overview

Java API for executing SQL statements
JDBC is a low-level API that is the foundation of advanced APIs
The user only focuses on the SQL statement itself
JDBC Features
Establish a connection to the database
Send SQL statement
Processing results
Support for two-tier models (applets) and three-tier models
Differences from ODBC
ODBC uses the C language interface and is not suitable for use in Java environments
Java calls local C code has many drawbacks in terms of security, implementation, robustness, and automatic portability of programs
JDBC is built on the basis of ODBC and retains the basic design features of ODBC

JMS Technology

Defines a common Java language interface for messaging services that supports the most common messaging models
Publish/Subscribe Model
Dot-to-point model
Message-oriented communication through access to the JMS API
JMS is often used to implement loose integration between heterogeneous systems

The message is asynchronous
Allow communication between different applications
Messaging applications are peer-
There is no clear boundary between the server and the client
Message producers can consume messages, and applications that consume messages can also produce messages

JTA and JTS, JCA

JTA (Java Transaction API) is a high-level, implementation-agnostic, protocol-independent API that applications and application servers can use to access transactions using JTA
JTS (Java Transaction Service) specifies the implementation specification for JTA-enabled transaction managers
Java mapping for the object Transaction Service (OTS) 1.1 specification under the high-level API
JTS using IIOP to propagate transactions
JTA and JTS Let the Java EE Application Server complete transaction management
Developers simply declare transaction management properties in the deployment descriptor, allowing the EJB component to participate in the transaction, which is the application server responsible for the management of the transaction

Java Connector Architecture (JCA)
Allows a resource adapter that supports access to the EIS to be inserted into the Java EE product
Defines the connection management contract between the Java EE Server and the resource adapter, allowing the connection pool to be established to the EIS
Defines the transaction management contract between the transaction manager and the EIS, and supports transactional access
Also supports transactions that are managed entirely by the EIS
Defines a security contract that enables secure access to the EIS

XML_RPC Basic Concepts

Is the core technology of Web services in the Java EE 1.4 Platform
An RMI-like RPC mechanism that specifies the Jax-RPC Runtime environment
Defining XML data types and WSDL (Web Services Description Language)
Mappings to Java types
Defining the Jax-RPC client programming model
Stub interfaces, dynamic proxies, dynamic calls
Defining a servlet-based server-side site model
Defining the SOAP Message Handler framework
Extended framework to provide complex Java database type mappings

JAXM

Used to send and receive soap-based messages
Define two models for sending and receiving messages
Request-response model: a blocking-based point-to-point model
One-way model: forwarding via JAXM message provider
Technical Advantages of JAXM
Send document-oriented data
Send large, coarse-grained, and complex stream data
Need to use asynchronous data exchange model
Need to ensure that each data is received by the other party

JMX (Java Management Extensions)

Framework for embedding management functions for applications, devices, systems, etc.
Assembly Layer: Define the information model, the various management objects in JMX exist in the form of management artifacts
Agent layer: Define various services and communication models, the Mbean server is the core and all management artifacts (including protocol adapters and connectors) must be registered with it before they can be managed
Distributed Service Tiers: includes protocol adapters and connectors for both types of components, defining management interfaces and artifacts that can operate on the agent layer

The core technology composition of the Java EE

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.