Академический Документы
Профессиональный Документы
Культура Документы
Page 1 of 45
1. Encapsulation
2. Inheritance
3. Polymorphism
Class Principles:
Package Principles:
1. Package Dependency
The Benefits
Basics:
Benefits:
Think if it like this: if you use more than 1 dot you are
violating the principle.
Example:
• Bad (Common):
inventory.SalesInfo.Items.Count = 2500;
• Good:
SalesInfo si = inventory.SalesInfo;
I know via reading and experience that this idea does help
decouple your code. You are able to re-use and place your
code under test coverage more easily.
What I mean is, if you have more than 1 dot in your call (i.e.,
person.spouse.name (bad) instead of person.GetSpouseName()
(good)) you are most likely violating LoD.
• Without principle :
return agency.searchJob();
• With principle:
return company.searchJob();
Package Dependency:
We also know that any Java class may reside in only a single
package.
This leads us to the basis for this principle, and it should now be
apparent that the packages into which classes are placed have
a tremendous impact on reuse.
The problem with this code is that, because the classes in these
packages are coupled, the two packages become tightly
coupled, which has a tremendous impact on REP
Mikalai Notes - Chapter 1
Page 19 of 45
Mikalai Notes - Chapter 1
Page 20 of 45
Tiers include client (both GUI and web), web (web container), business
(EJB container), integration, and resource tiers.
Java EE Clients
1. Web Clients
However, client systems will likely need the Java Plug-in and
possibly a security policy file for the applet to successfully
execute in the web browser.
Web components (Servlets, JSF or JSP) are the preferred API for
creating a web client program because no plug-ins or security
policy files are needed on the client systems.
2. Application Clients
Figure below shows the various elements that can make up the
client tier.
Web Components
Java EE web components are either servlets or pages
created using JSP technology (JSP pages) and/or
JavaServer Faces technology.
Servlets are Java programming language classes that
dynamically process requests and construct responses.
JSP pages are text-based documents that execute as
servlets but allow a more natural approach to creating
static content.
JavaServer Faces technology builds on servlets and JSP
technology and provides a user interface component
framework for web applications.
Static HTML pages and applets are bundled with web
components during application assembly but are not
Mikalai Notes - Chapter 1
Page 27 of 45
Business Components
Business code, which is logic that solves or meets the
needs of a particular business domain such as banking,
retail, or finance, is handled by enterprise beans
running in the business tier.
Figure below shows how an enterprise bean receives
data from client programs, processes it (if necessary),
and sends it to the enterprise information system tier
for storage.
An enterprise bean also retrieves data from storage,
processes it (if necessary), and sends it back to the
client program.
The enterprise information system (EIS) tier handles EIS
software and includes enterprise infrastructure systems
such as enterprise resource planning (ERP), mainframe
transaction processing, database systems, and other
legacy information systems.
For example, Java EE application components might
need access to enterprise information systems for
database connectivity.
Mikalai Notes - Chapter 1
Page 29 of 45
Java EE Application
A Java EE application is packaged into one or more
standard units for deployment to any Java EE platform-
compliant system. Each unit contains:
Java EE 5 APIs
Mikalai Notes - Chapter 1
Page 32 of 45
There are two kinds of enterprise beans: session beans and message-driven
beans. A session bean represents a transient conversation with a client. When
the client finishes executing, the session bean and its data are gone. A message-
driven bean combines features of a session bean and a message listener,
allowing a business component to receive messages asynchronously.
Commonly, these are Java Message Service (JMS) messages.
In Java EE 5, entity beans have been replaced by Java persistence API entities.
An entity represents persistent data stored in one row of a database table. If the
client terminates, or if the server shuts down, the persistence manager ensures
that the entity data is saved.
Java servlet technology lets you define HTTP-specific servlet classes. A servlet
class extends the capabilities of servers that host applications that are accessed
by way of a request-response programming model. Although servlets can
respond to any type of request, they are commonly used to extend the
applications hosted by web servers.
JavaServer Pages (JSP) technology lets you put snippets of servlet code directly
into a text-based document. A JSP page is a text-based document that contains
two types of text: static data (which can be expressed in any text-based format
such as HTML, WML, and XML) and JSP elements, which determine how the
page constructs dynamic content.
JSTL has iterator and conditional tags for handling flow control, tags for
manipulating XML documents, internationalization tags, tags for accessing
databases using SQL, and commonly used functions.
• JavaServer Faces
Input validation
Event handling
All this functionality is available using standard Java APIs and XML-based
configuration files.
The Java Message Service (JMS) API is a messaging standard that allows Java
EE application components to create, send, receive, and read messages. It
enables distributed communication that is loosely coupled, reliable, and
asynchronous.
The Java Transaction API (JTA) provides a standard interface for demarcating
transactions. The Java EE architecture provides a default auto commit to handle
transaction commits and rollbacks. An auto commit means that any other
applications that are viewing data will see the updated data after each database
read or write operation.
• JavaMail API
Java EE applications use the JavaMail API to send email notifications. The
JavaMail API has two parts: an application-level interface used by the
application components to send mail, and a service provider interface. The Java
EE platform includes JavaMail with a service provider that allows application
components to send Internet mail.
The Java API for XML Processing (JAXP), part of the Java SE platform,
supports the processing of XML documents using Document Object Model
(DOM), Simple API for XML (SAX), and Extensible Stylesheet Language
Transformations (XSLT). JAXP enables applications to parse and transform
XML documents independent of a particular XML processing implementation.
JAXP also provides namespace support, which lets you work with schemas that
might otherwise have naming conflicts. Designed to be flexible, JAXP lets you
use any XML-compliant parser or XSL processor from within your application
and supports the W3C schema.
The JAX-WS specification provides support for web services that use the JAXB
API for binding XML data to Java objects. The JAX-WS specification defines
client APIs for accessing web services as well as techniques for implementing
web service endpoints.
The Web Services for J2EE specification describes the deployment of JAX-WS-
based services and clients. The EJB and servlet specifications also describe
aspects of such deployment. It must be possible to deploy JAX-WS-based
applications using any of these deployment models.
The JAX-WS specification describes the support for message handlers that can
process message requests and responses. In general, these message handlers
execute in the same container and with the same privileges and execution
context as the JAX-WS client or endpoint component with which they are
associated.
The Java Architecture for XML Binding (JAXB) provides a convenient way to
bind an XML schema to a representation in Java language programs. JAXB can
be used independently or in combination with JAX-WS, where it provides a
standard data binding for web service messages. All Java EE application client
containers, web containers, and EJB containers support the JAXB API.
The SOAP with Attachments API for Java (SAAJ) is a low-level API on which
JAX-WS and JAXR depend. SAAJ enables the production and consumption of
messages that conform to the SOAP 1.1 specification and SOAP with
Attachments note. Most developers do not use the SAAJ API, instead using the
higherlevel JAX-WS API.
The Java API for XML Registries (JAXR) lets you access business and general-
purpose registries over the web. JAXR supports the ebXML Registry and
Repository standards and the emerging UDDI specifications. By using JAXR,
developers can learn a single API and gain access to both of these important
registry technologies.
The Java Database Connectivity (JDBC) API lets you invoke SQL commands
from Java programming language methods. You use the JDBC API in an
enterprise bean when you have a session bean access the database.
You can also use the JDBC API from a servlet or a JSP page to access the
database directly without going through an enterprise bean.
The JDBC API has two parts: an application-level interface used by the
application components to access a database, and a service provider interface to
attach a JDBC driver to the Java EE platform.
The Java Naming and Directory Interface (JNDI) provides naming and directory
functionality, enabling applications to access multiple naming and directory
services, including existing naming and directory services such as LDAP, NDS,
DNS, and NIS. It provides applications with methods for performing standard
directory operations, such as associating attributes with objects and searching
for objects using their attributes.
Using JNDI, a Java EE application can store and retrieve any type of named
Java object, allowing Java EE applications to coexist with many legacy
applications and systems.
Java EE naming services provide application clients, enterprise beans, and web
components with access to a JNDI naming environment. A naming environment
allows a component to be customized without the need to access or change the
component's source code.
The Java Authentication and Authorization Service (JAAS) provides a way for
a Java EE application to authenticate and authorize a specific user or group of
users to run it.
Container Services
Containers are the interface between a component and the low-level platform-
specific functionality that supports the component.
For example, an enterprise bean can have security settings that allow it a certain
level of access to database data in one production environment and another level
of database access in another production environment.
Communication Technologies
Internet protocols
Internet protocols define the standards by which the different pieces of the
J2EE platform communicate with each other and with remote entities. The
J2EE platform supports the following Internet protocols:
• SSL 3.0 - Secure Socket Layer. A security protocol that provides privacy
over the Internet. The protocol allows client-server applications to
communicate in a way that cannot be eavesdropped or tampered with.
Servers are always authenticated and clients are optionally authenticated.
Mikalai Notes - Chapter 1
Page 43 of 45
The J2EE platform supports the JRMP protocol, the transport mechanism for
communication between objects in the Java language in different address
spaces.
Object Management Group (OMG) protocols allow objects hosted by the J2EE
platform to access remote objects developed using the OMG's Common Object
Request Broker Architecture (CORBA) technologies and vice versa. CORBA
objects are defined using the Interface Definition Language (IDL).
ORBs communicate with each other using the Internet Inter-ORB Protocol
(IIOP). The OMG technologies required by the J2EE platform are Java IDL and
RMI-IIOP.
1. Java IDL
Java IDL allows Java clients to invoke operations on CORBA objects that have
been defined using IDL and implemented in any language with a CORBA
mapping. Java IDL is part of the J2SE platform. It consists of a CORBA API
and ORB. An application component provider uses the idlj IDL compiler to
generate a Java client stub for a CORBA object defined in IDL. The Java client
is linked with the stub and uses the CORBA API to access the CORBA object.
Mikalai Notes - Chapter 1
Page 44 of 45
2. RMI-IIOP
Messaging Technologies
JMS messages are used to coordinate these applications. The JavaMail API
provides an interface for sending and receiving messages intended for users.
Although either API can be used for asynchronous notification, JMS is
preferred when speed and reliability are a primary requirement.
The Java Message Service (JMS) API allows J2EE applications to access
enterprise messaging systems such as IBM MQ Series and TIBCO Rendezvous.
JMS messages contain well-defined information that describe specific business
actions. Through the exchange of these messages, applications track the
progress of enterprise activities. The JMS API supports both point-to-point and
publish-subscribe styles of messaging.
2. JavaMail API
Mikalai Notes - Chapter 1
Page 45 of 45
The JavaMail API provides a set of abstract classes and interfaces that comprise
an electronic mail system. The abstract classes and interfaces support many
different implementations of message stores, formats, and transports. Many
simple applications will only need to interact with the messaging system
through these base classes and interfaces.
Data Formats
Data formats define the types of data that can be exchanged between
components. The J2EE platform requires support for the following data formats:
2. Image files - The J2EE platform supports two formats for image files:
GIF (Graphics Interchange Format), a protocol for the online
transmission and interchange of raster graphic data, and JPEG (Joint
Photographic Experts Group), a standard for compressing gray-scale or
color still images.
4. Class file - The format of a compiled Java file as specified in the Java
Virtual Machine specification. Each class file contains one Java language
type - either a class or an interface - and consists of a stream of 8-bit
bytes.