0% found this document useful (0 votes)
41 views36 pages

DT Notes Unit II

The document provides an overview of the J2EE (Java 2 Enterprise Edition) architecture and framework. It describes the key components of J2EE including application clients, applets, web components, server components, and roles. It also discusses the .NET framework architecture including its tiered and modular structure with languages, common language runtime, and framework class library at different levels. The common language runtime converts MSIL code to native machine language and provides memory management, exception handling and other services.

Uploaded by

thiyaguvalangai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views36 pages

DT Notes Unit II

The document provides an overview of the J2EE (Java 2 Enterprise Edition) architecture and framework. It describes the key components of J2EE including application clients, applets, web components, server components, and roles. It also discusses the .NET framework architecture including its tiered and modular structure with languages, common language runtime, and framework class library at different levels. The common language runtime converts MSIL code to native machine language and provides memory management, exception handling and other services.

Uploaded by

thiyaguvalangai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

M. Gnanasekaran, MCA., M.Phil., SET.

, TVKGAC-TVR DT – Unit_II Notes

J2EE
1.1 Introduction
Java 2 Enterprise Edition, or J2EE, is a package of specifications aligned to enable the
development of multi-tier enterprise applications. The specifications outline the various
components needed within a J2EE enterprise system, the technologies for accessing and providing
services, and even the roles played during the development, deployment, and runtime lifecycle.
The combination of these specifications introduced faster and more streamlined development
processes, to the software industry, that have been mapped onto common software methodologies
such as RUP, XP, and others.

J2EE has fast become the de facto standard for developing and deploying enterprise systems. It
represents Sun’s attempt to take their Java mantra of “Write Once, Run Anywhere” to the next
level and make it “Write Once, Deploy Anywhere.” While using it is not as easy as dropping
new code fragments into existing code, J2EE has made significant strides in easing the burden on
the developers and deployers of a system.

J2EE Architecture
J2EE, introduced in 1998, defines a multi-tier architecture for enterprise information
systems (EIS). By defining the way in which multi-tier applications should be developed, J2EE
reduces the costs, in both time and money, of developing large-scale enterprise systems. Figure
1.5 illustrates the J2EE architecture.
The J2EE platform specifies the logical application components within a system and defines the
roles played in the development process.

PAGE NO. 1
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes

Application components

Four application components are defined within the J2EE platform. They are as follows.
✦ Application clients (Standalone Java clients)
✦ Applets (Java code which executes within a browser)
✦ Web components (JSPs, Servlets)
✦ Server components (EJBs, J2EE API implementations)
A product does not need to support all types of components the norm is to provide an
implementation to support a particular component type. However, all components are similar in
that they run within a container. The container is responsible for providing the runtime
environment, the mechanism for identifying and understanding the file formats used for
deployment, and the standard services for application components to use.
The four application components are discussed in the following sections.
Application clients
Clients are generally stand-alone applications written in Java. They run within a virtual
machine and can use the J2EE standard services to access components located within another
tier. The J2EE standard services are usually provided on the client via an installation of J2SE, or
along with the distribution of the application itself.
Applets
Applets are similar to application clients, but execute within a Web browser. Initially
applets garnered extensive attention, as they were seen as a means of making Web pages more
dynamic. Most Web browsers have an embedded Java Virtual Machine (JVM) however, the Java
plugin can be used to force the browser to use a particular version of JVM.
Web components
Although the term can be misleading, Web components do not execute on the client side.
Web components are server-side components, generally used to provide the presentation layer to
be returned to a client. Two types of Web components exist: Java Server Pages (JSPs) and Java
servlets. Very basically, JSPs are similar to regular HTML pages but contain embedded Java
code while Java servlets are Java classes that use Java’s I/O application programming interfaces
(APIs) to output HTML to the client. Both JSPs and servlets can be used to output other format

PAGE NO. 2
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
types.

Server components
Server components come in the form of Enterprise JavaBeans (EJBs). EJBs execute within
a container that manages the runtime behavior of the EJB. EJBs are usually where the business
logic for an enterprise system resides.
Roles
The roles specified within the J2EE are those played during the development and
deployment cycles of an enterprise application. While the roles are distinct, in reality multiple roles
tend to be filled by the same organization.
The following roles are discussed in this section.
✦ J2EE product provider
✦ Application component provider
✦ Application assembler
✦ Deployer
✦ System administrator
✦ Tool provider
✦ System component provider
The J2EE product provider
A J2EE product provider is a company that provides a product that implements a part of
the J2EE specification. For example, one company may provide a product that implements the
J2EE container for EJBs, and another may provide a product that provides an implementation for
a JMS server.
The application component provider
An application component provider is a developer who creates a component that isintended
to reside within one of the J2EE containers. The application component providerdevelops application
components adhering to the J2EE API specifications with the intention that the component will be
deployed within a J2EE Server. This enables a developer to select a different J2EE product provider
without modifying the component. Application componentproviders develop a range of components,
including EJBs, HTML pages, and other Web components.

PAGE NO. 3
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes

The application assembler


An application assembler generally uses various application components to create asingle
application for distribution. Generally, in a large project, one team will be responsible for
developing the Web components, another for the business-logic components, and perhaps another
for the data-object components. The application assembler would package the various components
and then distribute them as an enterprise archive (.ear) file.
The deployer
The deployment of an enterprise application nearly always requires a different
configuration for each rollout. J2EE has taken this into consideration by specifying the role of
deployer. The deployer is responsible for configuring the applications developed by the application
assembler for execution within a platform provided by the J2EE product provider.
The system administrator
A system administrator generally uses tools provided by a tool provider to monitor the
runtime environment and to ensure that services are performing optimally. Various tools are
available on the market, ranging from those which allow for monitoring the system as a whole, to
runtime inspection on individual services to help determine where bottlenecks may reside.
The tool provider
The J2EE specification also provides tools to make development easier and to monitorthe
runtime environment. Tools vary from integrated development environments to runtime-
performance products.
The system-component provider
Many system components are available for the J2EE architecture. The J2EE architecture
provides ways to introduce these new components for accessing services such as existing
messaging systems, transaction services, and others, such as billing systems that may be industry-
specific. Using the connector architecture is one way to introduce these new components.

PAGE NO. 4
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes

Dot NET Framework Architecture


.NET is tiered, modular, and hierarchical. Each tier of the .NET Framework is a layer of
abstraction. .NET languages are the top tier and the most abstracted level. The common language
runtime is the bottom tier, the least abstracted, and closest to the native environment. This is
important since the common language runtime works closely with the operating environment to
manage .NET applications. The .NET Framework is partitioned into modules, each with its own
distinct responsibility. Finally, since higher tiers request services only from the lower tiers, .NET
is hierarchical. The architectural layout of the .NET Framework is illustrated in Figure 1.6.

Figure 1.6 An overview of the .NET architecture.

PAGE NO. 5
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes

The .NET Framework is a managed environment. The common language runtime monitors
the execution of .NET applications and provides essential services. It manages memory, handles
exceptions, ensures that applications are well-behaved, and much more. Language interoperability
is one goal of .NET. .NET languages share a common runtime (the common language runtime, a
common class library), the Framework Class Library (FCL), a common component model, and
common types. In .NET, the programming language is a lifestyle choice. Except for subtle
differences, C#, VB.NET, or JScript.NET offer a similar experience.
Common Language Runtime (CLR)
The CLR is the heart of .NET framework. It is .NET equivalent of Java Virtual Machine
(JVM). It is the runtime that converts a MSIL (Micro Soft Intermediate Language) code into the
host machine language code, which is then executed appropriately.
The CLR provides a number of services that include
• Loading and execution of codes
• Memory isolation for application
• Verification of type safety
• Compilation of IL into native executable code
• Providing metadata
• Automatic garbage collection
• Enforcement of Security
• Interoperability with other systems
• Managing exceptions and errors
• Provide support for debugging and profiling
Common Type System (CTS)
The language interoperability, and .NET Class Framework, are not possible without all the
language sharing the same data types. What this means is that an “int” should mean the same in
VB, VC++, C# and all other .NET compliant languages. Same idea follows for all the other data
types. This is achieved through introduction of Common Type System (CTS).
CTS, much like Java, define every data type as a Class. Every .NET compliant language must stick
to this definition. Since CTS defines every data type as a class this means that only Object-
Oriented (or Object-Based) languages can achieve .NET compliance.

PAGE NO. 6
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes

Common Language Specification (CLS)


One of the obvious themes of .NET is unification and interoperability between various
programming languages. In order to achieve this certain rules must be laid and all the languages
must follow these rules. In other words we can not have languages running around creating their
own extensions and their own fancy new data types. CLS is the collection of the rules and
constraints that every language (that seeks to achieve .NET compatibility) must follow. Microsoft
has defined three level of CLS compatibility/compliance. The goals and objectives of each
compliance level have been set aside. The three compliance levels with their brief description are
given below.
Compliant producer
The component developed in this type of language can be used by any other language.
Consumer
The language in this category can use classes produced in any other language. In simple
words this means that the language can instantiate classes developed in other language. This is
similar to how COM components can be instantiated by your ASP code.
Extender
Languages in this category can not just use the classes as in CONSUMER category but can
also extend classes using inheritance. Languages that come with Microsoft Visual Studio namely
Visual C++, Visual Basic and C# all satisfy the above three categories. Vendors can select any of
the above categories as the targeted compliance level(s) for their languages.
Microsoft Intermediate Language (MSIL)
A .NET programming language (C#, VB.NET, J# etc.) does not compile into executable
code instead it compiles into an intermediate code called Microsoft Intermediate Language
(MSIL). As a programmer one need not worry about the syntax of MSIL - since our source code
in automatically converted to MSIL. The MSIL code is then send to the CLR (Common Language
Runtime) that converts the code to machine language which is then run on the host machine.
MSIL is similar to Java Byte code. A Java program is compiled into Java Byte code (the .class
file) by a Java compiler, the class file is then sent to JVM which converts it into the host machine
language.

PAGE NO. 7
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes

Managed Code
The role of CLR doesn‘t end once we have compiled our code to MSIL and a JIT compiler
has compiled this to native code. Code written using the .NET framework, is managed code when
it is executed. This stage is usually referred to as being at runtime. This means thatthe CLR
looks after our applications, by managing memory, handling security, allowing cross language
debugging and so on. By contrast, applications that do not run under the control of the CLR are
said to be unmanaged and certain languages such as C++ can be used to write such applications,
that for example, to access low level functions of the operating systems. Howeverin C# we can
only write code that runs in a managed environment.
Unified classes
The term .NET framework refers to the group of technologies that form the development
foundation for the Microsoft .NET platform. The key technologies in this group are the run time
and the class libraries. The run time is responsible for managing your code and providing
services to it while it executes, playing a role similar to that of the Visual Basic 6.0 run time. The
.NET programming languages including Visual Basic .NET, Microsoft Visual C# and C++
managed extensions and many other programming languages from various vendors utilize .NET
services and features through a common set of unified classes.
The .NET unified classes provide foundation of which you build your applications, regardless of
the language you use. Whether you simply concating a string, or building a windows Services or
a multiple-tier web-based applications, you will be using these unified classes.
The unified classes provide a consistent method of accessing the platforms functionality. Once you
learn to use the class library, you will find that all tasks follow the same uniform architecture, you
no longer need to learn and master different API architecture to write your applications.
By building your applications on a unified, integrated framework, you maximize your return on
the time you spend learning this framework, and you end up with more robust applications that are
easy to deploy and maintain.

Just In Time Compiler


• To make it easy for language writers to port their languages to .NET, Microsoft
developed a language akin to assembly language called Microsoft intermediate language (MSIL).

PAGE NO. 8
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes

To compile applications for .NET, compilers take source code as input and produce MSIL as
output.
• MSIL itself is a complete language that you can write applications in. However, as with
assembly language, you would probably never do so except in unusual circumstances. Because
MSIL is its own language, each compiler team makes its own decision about how much of the
MSIL it will support. However, if you're a compiler writer and you want to create a language that
does interoperate with other languages, you should restrict yourself to features specified by the
CLS. See the figure 1.6.1

Figure 1.6.1 Microsoft Intermediate Language

• You write source code in C# and compile it using the C# compiler (csc.exe) into an
EXE.

• The C# compiler outputs the MSIL code and a manifest into a read-only part of the
EXE that has a standard PE (Win32-portable executable) header. When the compiler
creates the output, it also imports a function named _ CorExeMain from the .NET
runtime.

PAGE NO. 9
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
• When the application is executed, the operating system loads the PE, as well as
any dependent dynamic-link libraries (DLLs), such as the one that exports the _
CorExeMain function (mscoree.dll), just as it does with any valid PE.
Framework Base Classes
The .NET Framework has an extensive set of class libraries. This includes classes for
• Data Access: High Performance data access classes for connecting to SQL
Server or anyother OLEDB provider
• XML Supports: Next generation XML support that goes far beyond the
functionality ofMSXML
• Directory Services: Support for accessing Active Directory/LDPA using ADSI
• Regular Expression: Support for above and beyond that found in Perl 5
• Queuing Supports: Provides a clean object-oriented set of classes for
working withMSMQ
These class libraries use the CLR base class libraries for common functionality.
Base Class Libraries
The Base class library in the .NET Framework is huge. It covers areas such as
• Collection : The System.Collections namespaes provides numerous collection
classes
• Thread Support: The System.Threading namespace provides support for creating
fast, efficient, multi-threaded application
• Code Generation: The System.CodeDOM namespace provides classes for
generating source files in numerous languages. ASP.NET uses these classes when
converting ASP.NET pages into classes, which are subsequently compiled
• IO: The System.IO provides extensive support for working with files and all other
streamtypes
• Reflection: The System.Reflection namespace provides support for load
assemblies,examining the type with in assemblies, creating instances of types, etc
• Security: The System.Security namespace provides support for services such as
authentication, authorization, permission sets, policies, and cryptography. These
base services are used by application development technologies like ASP.NET to
build their security infrastructure

PAGE NO. 10
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
Model-View-Controller (MVC) Architecture
The MVC paradigm provides a pattern for separating the presentation logic
(view),business logic (control), and data objects (model). J2EE’s architecture maps onto
the MVC nicely. Typically, entity beans are used to provide the model logic, while a mix
of entity beans and session beans are used to provide the control logic, and Web
components are used to implement both control and presentation logic. In practice,
however, the separation of the three types of logic is not as distinct, and additional patterns
are often needed to support the development cycle. Figure 1.7 shows how the three
different logical functional blocks work together.

1.7 MVC Architecture

The model
The M in MVC refers to the data object model. For example, in an airline ticketing
service you may have the concept of a booking, which in the real world is represented by
a paperticket. The model deals with issues such as how the booking is represented within
the software system, where it is persisted, and how it is accessed. For example, the
booking may be held within a relational database within a table named Bookings with
the fields PassengerName, DepartureCity, DestinationCity, TravelDate, and
DepartureTime. This data may be accessedvia JDBC using Entity Beans.

The view
The view is responsible for presentation issues. It handles how the client will see
the application, and so HTML issues are usually deal with here. However, other markup

PAGE NO. 11
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
languages such as Wireless Markup Language (WML) and Extensible Markup Language
(XML) are increasingly being used to support more varied types of clients. The Booking
example may be displayed in various ways. For example, on a wireless device only the
most relevant information might be displayed due to the limited screen size. In fact, the
term view may be misleading, implying that it is meant for visual display only, the view
may also be used to present the model via an audio interface if desired. The method in
which the model is presented is abstracted from the underlying data.

The control
The control part of the paradigm deals with the business logic of the application.
It handles how and when a client interacting with the view is able to access the model.
The control layer usually interacts with authorization and authentication services, other
J2EE services, and external systems to enforce the business rules to be applied to the
application. In our Booking example, the control would determine whether the view can
actually display the model. This maybe based on whether the user is logged in, if he or
she has appropriate authorization and so on. It would also hold the business logic of what
to do if the user attempts to view a booking that no longer exists for example, should an
error be presented to the user? Should the user be prompted with a screen asking for
additional information? These are rules that change within the business but they do not
necessarily force a change on the view or model. To support the MVC, the J2EE
architecture also provides a varied set of APIs to help facilitate the separation
between themodel, view, and control functional blocks within an application.

Java Beans
JavaBeans is one of the reusable class code elements often applied on java-based
software application programming. Here, Beans can be defined as a way of encompassing
multiple objects beneath a single object. The JavaBeans class components can be labelled
as methods, events, properties and persistence. This type of class is advantageous over
others due to its notable reusability characteristics, enables object communication,
platform-independent, shorter time consumption, requires lesser manual efforts, etc.

PAGE NO. 12
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
Understanding JavaBeans

As stated, JavaBeans helps in reusing software components in developing an


application. With the help of JavaBeans, one can reuse software components that other
developers write. This eliminates the need for understanding inner workings. As Beans
consists of numerous objects into a single object, one can directly access this object from
various places. Its maintenance is easy. The software component model deals with the
creation and reuse of the software components to build an application. With the help of the
builder tool, one can develop new beans or use existing beans to create an application. One
can directly use these beans in the software.

If you are still confused, then consider the example of a worker assembling a car, and
the radio is one of the components. Instead of manufacturing the radio from scratch, a worker
can directly assemble the radio to the car. This eliminates the need for manufacturing a radio
for assembly.

Components of JavaBeans

Components of Java Beams are nothing but the class that contains the definition of
beans. These classes have specific design convections. It consists of events, methods,
persistence, properties. Non-GUI based and GUI based components are the two types of
components. The classes are discussed below:
• Properties: This attribute consists of a label, font, color, size, display size, etc. It
determines behavior, appearance, and the state of Beam.
• Methods: Methods in JavaBeans are similar to the normal Java methods. It does have
any specific naming convention.
• Events: Events in JavaBeans is similar to Swing event handling.
• Persistence: It helps in storing the state of JavaBean.

What Can You do with JavaBeans?


As there are no restrictions on the capabilities of JavaBeans, one can design any type of
component in this. With JavaBeans, one can reuse software components in any environment.
From simple functions like spelling correction to complex functions like forecasting the stock
market, beans can perform different functions. Beans can be visible or invisible to the end-user.
With a set of distributed components, beans can work autonomously. From set data points, the
software can generate a pie chart. This is the example of a locally executed bean. Bean that

PAGE NO. 13
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
delivers real-time price information about the stock market is also one of the examples of
this.
Beans can also be used to give interactive capabilities to web-based applications. Beans can
run on any operating system. It can run inside numerous application environments such as word
processors, browser and many other applications. A UI component such as trees, graphical
buttons, and trees gives a lively touch to applications and eliminates the need to write custom
components. One can develop the JavaBeans with Beans Development Kit (BDK) from Sun.

Advantages of JavaBeans
1. Run anywhere; write once- Java Beans eliminates the need for writing software again and
again.
2. One can work with JavaBeans on Numerous local platforms, which make it valuable in the
global market.
3. JavaBeans can capture the events that are sent by other objects. It enables object
communication.
4. An application developer is able to control Methods, events, and the properties of any Java
beans.
5. Zero hassle at run time with auxiliary software; one can configure beans during design time.
6. Reusable: One can make a persistence configuration setting in JavaBeans. Persistent storage
and restoration later can save the configuration setting of the bean.

Required Skills for JavaBeans

• It is vital to have a proper understanding of computer fundamentals, algorithms,


structure, etc. One should have an understanding of numerous operating systems of the
computer.
• One must have a proper understanding of the Java 1.1 event model. One should be
aware of different Java technologies.
• While developing operation names in the Java Bean class, it is important to follow
certain ‘naming conventions.
• One should be aware of the information of the builder tools to develop JavaBeans.
• The basic knowledge of different frameworks and fluency coding will surely give one
edge in developing JavaBeans.

PAGE NO. 14
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
Career Scope in this Technology
In today’s interconnected world, programming language plays a pivotal role in the business
world. Java is considered as one of the reliable programming languages in the world. It is a
very popular language among developers. The scope and carriers in developing JavaBeans
expected to rise in the coming years. Professionals with Java skills have a lot of opportunities
in these sectors. Today Java is the leading programming language in the back-end market and
application development. The future looks promising for all java professionals across the globe.
Millions of Java Developers prefer Java for its usability, practicality, compatibility, and ease
of use.
There is plenty of Java opportunities present across the globe. Numerous reputed companies
like Microsoft, Amazon web services, IBM, Oracle, and many others are always looking for
Java professionals.
JavaBean Professionals can make a flourishing carrier in Information Technology. Everyone
has different reasons for picking up different technology, but having knowledge of JavaBeans
surely benefits one’s skill set and offers a lot of growth opportunities and money.

Enterprise Java Beans

Introduction
• EJB stands for enterprise java beans.
• EJB java beans is server side component.
• EJB is an essential part of J2EE platform
• J2EE application containers contains the components that can be used by client for
executing business logic
• EJB mainly contains the business logic and business data.
• EJB components always lie in some container which is called EJB container EJB
component is an EJB class which is written by developer that implement business logic.
• It is a specification provided by Sun Microsystem to develop secured , robust and scalable
distributed application.
• To run EJB application, you need application server (EJB container) such as, Jboss,
Glassfish.
• EJB application is deployed on the server, so is called server side component also

PAGE NO. 15
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
• EJB container performs: -life cycle management -Security -Transaction management -
object pooling
EJB Architecture Java
Java beans incorporate a set of objects into one accessible object that can be accessed
easily from any application. This single accessible object is maintainable, customizable,
and reusable. The setter/getter method and the single public constructor are used to
govern that single accessible object. We can update and read the value of any variable
of any object by using the setter and getter, respectively.

The EJB stands for Enterprise Java beans that is a server-based architecture that
follows the specifications and requirements of the enterprise environment. EJB is
conceptually based on the Java RMI(Remote Method Invocation) specification. In EJB,
the beans are run in a container having four-tier architecture. This architecture consists
of four layers, i.e., Client layer, Web layer, Application layer, and Data layer.

Architecture
The EJB architecture has two main layers, i.e., Application Server and EJB Container,
based on which the EJB architecture exist. The graphical representation of the EJB
architecture is given below.

In the above diagram, the logical representation of how EJBs are invoked and deployed
by using RMI(Remote Method Invocation) is defined. The containers of the EJB cannot
be self-deployed. In order to deploy the containers, it requires the Application server.

Application Server
In the EJB architecture, the Application server is the outermost layer that holds or
contains the Container to be deployed. The application layer plays an important role
in executing the application developed using the beans. It provides the necessary
environment to execute those applications. Some most popular application servers are

PAGE NO. 16
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
Web-logic, Tomcat, JBoss, Web-sphere, Wildfly, and Glass-finish. The main tasks of the
application server are:

1. Manage Interfaces
2. Execution of the processes
3. Connecting to the database
4. Manage other resources.

Container
In EJB architecture, the Container is the second outermost layer. It is a very important
layer for enterprise beans that are contained in it. For the enterprise bean, the
Container provides various supporting services, which are as follows:

o It provides support for transactional services such as registering the objects, assign
remote interfaces, purge the instances.
o It provides support for monitoring the object's activities and coordinating distributed
components.
o It provides support for security services.
o It provides support for the pooling of resources.
o It provides support for managing the Life-cycle of beans and their concurrency.
o It provides support to concentrate on business logic.

Beans
Java beans of the enterprise are installed in the Container in the same way as a Plain
old java object (POJO) is installed and registered to the Container. For developing
secured, large scale and robust business applications, beans provide business logic.

Types of EJB
There are three types of Enterprise Java Beans or EJB available, which are as follows:

a. Stateless Enterprise Java Beans


b. Stateful Enterprise Java Beans
c. Message-driven Enterprise Java Beans

Stateless EJB
In order to implement the stateless business logic, the stateless EJBs are primarily
used. Storing a user's physical address into an inventory system's database is an
example of the stateless EJB. In addition, a stateless bean would be perfect for this type

PAGE NO. 17
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
of business logic because it is not necessary to have more than two forms on the user
interface at all stages of the transaction.

StatelessBeanExample.java
1. package com.javatpoint.ejbarchitecture;
2. import javax.ejb.Stateless;
3.
4. @Stateless
5. public class StatelessBeanExample {
6. }
Stateful EJB
The Stateful EJB is just opposite to the Stateless EJB. The Stateful EJBs are used
when we have to maintain the state of the application on the backend during the user
session. The shopping cart of an online shopping application is an example of
the Stateful EJB. In order to achieve such application, we will use the following steps:

1. We will create the stateful session bean.


2. After that, for temporarily storing the selected products that are within the user session
on the backend, we have to create a global variable collection of type products.
3. Next, we will create a method through which we will add all the selected products to
the collection that we create in the previous step.
4. We also create a method through which we will remove the product from the
collection.
5. In the end, we will create a checkout method for the selected products to process.

StatelessBeanExample.java
1. package com.javatpoint.ejbarchitecture;
2. import javax.ejb.Stateful;
3.
4. @Stateful
5. public class StatelessBeanExample {
6. }
Message-driven EJB
Another special type of EJB that is used for sending and receiving messages from
message brokers implements the JMS specification. The systems based on the broker
are loosely coupled. The components that communicate through the broker have the

PAGE NO. 18
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
advantage of not waiting for one request to finish before submitting another request
because the broker by nature is asynchronous.

MessageDrivenBeanExample.java
package com.javatpoint.ejbarchitecture;
import javax.ejb.MessageDriven;
import javax.jms.MessageListener;
import javax.jms.Message;
import javax.ejb.ActivationConfigProperty;
@MessageDriven(mappedName = "jms/Queue", activationConfig = {
@ActivationConfigProperty(propertyName = "reciverType", propertyValue = "ja
vax.jms.Queue"),
@ActivationConfigProperty(propertyName = "reciver", propertyValue =
"java:/queue/testqueue")
})
public class MessageDrivenBeanExample implements MessageListener {
public MessageDrivenBeanExample() {
}
public void onMessage(Message message) {
System.out.println("Message received successfully .");
}
}
Difference b/w EJB and JB
These are the following differences between EJB and JB:

S.No. EJB JB
1. EJB is not visible because it runs as a JB is visible.
remote.
2. EJB is executed on the server-side. EJB can execute on both the client-side
and the server-side.
3. EJB works with an external builder tool For interpreting the bean's
or its IDE. functionality, EJB uses its external
interface.
4. EJB uses the technology of components By using generic components created
but cannot build or extend it over by Java beans, it is able to build applet
beans. and application.
5. It has no property editor, customizer, It has property editors, customizers,

PAGE NO. 19
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
and bean information classes. It has and bean information classes.
only information about what is
provided by the deployment
descriptor.
6. It supports transactions. It doesn't support transactions.
7. Three types of EJB possible. No types.

RMI (Remote Method Invocation)


1. Remote Method Invocation (RMI)
2. Understanding stub and skeleton
1. stub
2. skeleton
3. Requirements for the distributed applications
4. Steps to write the RMI program
5. RMI Example

The RMI (Remote Method Invocation) is an API that provides a mechanism to create
distributed application in java. The RMI allows an object to invoke methods on an

object running in another JVM.


The RMI provides remote communication between the applications using two

objects stub and skeleton.


Understanding stub and skeleton
RMI uses stub and skeleton object for communication with the remote object.
A remote object is an object whose method can be invoked from another JVM. Let's

understand the stub and skeleton objects:


stub
The stub is an object, acts as a gateway for the client side. All the outgoing requests
are routed through it. It resides at the client side and represents the remote object.

When the caller invokes method on the stub object, it does the following tasks:
1. It initiates a connection with remote Virtual Machine (JVM),
2. It writes and transmits (marshals) the parameters to the remote Virtual Machine (JVM),
3. It waits for the result
4. It reads (unmarshals) the return value or exception, and

PAGE NO. 20
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
5. It finally, returns the value to the caller.
skeleton
The skeleton is an object, acts as a gateway for the server side object. All the incoming

requests are routed through it. When the skeleton receives the incoming request, it
does the following tasks:

1. It reads the parameter for the remote method


2. It invokes the method on the actual remote object, and
3. It writes and transmits (marshals) the result to the caller.
In the Java 2 SDK, an stub protocol was introduced that eliminates the need for

skeletons.
Understanding requirements for the distributed applications
If any application performs these tasks, it can be distributed application.
.
1. The application need to locate the remote method
2. It need to provide the communication with the remote objects, and
3. The application need to load the class definitions for the objects.

The RMI application have all these features, so it is called the distributed application.
Java RMI Example
The is given the 6 steps to write the RMI program.
1. Create the remote interface
2. Provide the implementation of the remote interface

PAGE NO. 21
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
3. Compile the implementation class and create the stub and skeleton objects using the
rmic tool
4. Start the registry service by rmiregistry tool
5. Create and start the remote application
6. Create and start the client application
RMI Example
In this example, we have followed all the 6 steps to create and run the rmi application.
The client application need only two files, remote interface and client application. In

the rmi application, both client and server interacts with the remote interface. The
client application invokes methods on the proxy object, RMI sends the request to the

remote JVM. The return value is sent back to the proxy object and then to the client
application.

1) create the remote interface


For creating the remote interface, extend the Remote interface and declare the
RemoteException with all the methods of the remote interface. Here, we are creating

a remote interface that extends the Remote interface. There is only one method named
add() and it declares RemoteException.

PAGE NO. 22
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
1. import java.rmi.*;
2. public interface Adder extends Remote{

3. public int add(int x,int y)throws RemoteException;


4. }

2) Provide the implementation of the remote interface


Now provide the implementation of the remote interface. For providing the

implementation of the Remote interface, we need to


o Either extend the UnicastRemoteObject class,
o or use the exportObject() method of the UnicastRemoteObject class
In case, you extend the UnicastRemoteObject class, you must define a constructor that
declares RemoteException.

1. import java.rmi.*;
2. import java.rmi.server.*;

3. public class AdderRemote extends UnicastRemoteObject implements Adder

{
4. AdderRemote()throws RemoteException{

5. super();
6. }

7. public int add(int x,int y){return x+y;}


8. }
3) create the stub and skeleton objects using the rmic tool.
Next step is to create stub and skeleton objects using the rmi compiler. The rmic tool

invokes the RMI compiler and creates stub and skeleton objects.
1. rmic AdderRemote
4) Start the registry service by the rmiregistry tool
Now start the registry service by using the rmiregistry tool. If you don't specify the port

number, it uses a default port number. In this example, we are using the port number
5000.

1. rmiregistry 5000

PAGE NO. 23
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
5) Create and run the server application
Now rmi services need to be hosted in a server process. The Naming class provides

methods to get and store the remote object. The Naming class provides 5 methods.

In this example, we are binding the remote object by the name sonoo.
1. import java.rmi.*;
2. import java.rmi.registry.*;

3. public class MyServer{


4. public static void main(String args[]){

5. try{
6. Adder stub=new AdderRemote();

7. Naming.rebind("rmi://localhost:5000/sonoo",stub);
8. }catch(Exception e){System.out.println(e);}

9. }
10. }
6) Create and run the client application
At the client we are getting the stub object by the lookup() method of the Naming
class and invoking the method on this object. In this example, we are running the

server and client applications, in the same machine so we are using localhost. If you
want to access the remote object from another machine, change the localhost to the

host name (or IP address) where the remote object is located.


1. import java.rmi.*;

PAGE NO. 24
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
2. public class MyClient{

3. public static void main(String args[]){


4. try{

5. Adder stub=(Adder)Naming.lookup("rmi://localhost:5000/sonoo");
6. System.out.println(stub.add(34,4));

7. }catch(Exception e){}
8. }

9. }
10. For running this rmi example,
11.

12. 1) compile all the java files


13.

14. javac *.java


15.

16. 2)create stub and skeleton object by rmic tool


17.

18. rmic AdderRemote


19.

20. 3)start rmi registry in one command prompt


21.

22. rmiregistry 5000


23.

24. 4)start the server in another command prompt


25.

26. java MyServer


27.

28. 5)start the client application in another command prompt


29.

30. java MyClient

PAGE NO. 25
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
Output of this RMI example

PAGE NO. 26
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
Java Server Pages - JSP
JSP technology is used to create web application just like Servlet technology. It can be

thought of as an extension to Servlet because it provides more functionality than


servlet such as expression language, JSTL, etc.

A JSP page consists of HTML tags and JSP tags. The JSP pages are easier to maintain
than Servlet because we can separate designing and development. It provides some

additional features such as Expression Language, Custom Tags, etc.


Advantages of JSP over Servlet
There are many advantages of JSP over the Servlet. They are as follows:
1) Extension to Servlet
JSP technology is the extension to Servlet technology. We can use all the features of
the Servlet in JSP. In addition to, we can use implicit objects, predefined tags,

expression language and Custom tags in JSP, that makes JSP development easy.
2) Easy to maintain
JSP can be easily managed because we can easily separate our business logic with
presentation logic. In Servlet technology, we mix our business logic with the

presentation logic.
3) Fast Development: No need to recompile and redeploy
If JSP page is modified, we don't need to recompile and redeploy the project. The
Servlet code needs to be updated and recompiled if we have to change the look and

feel of the application.


4) Less code than Servlet
In JSP, we can use many tags such as action tags, JSTL, custom tags, etc. that reduces
the code. Moreover, we can use EL, implicit objects, etc.

The Lifecycle of a JSP Page


The JSP pages follow these phases:
o Translation of JSP Page
o Compilation of JSP Page
o Classloading (the classloader loads class file)

PAGE NO. 27
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
o Instantiation (Object of the Generated Servlet is created).
o Initialization ( the container invokes jspInit() method).
o Request processing ( the container invokes _jspService() method).
o Destroy ( the container invokes jspDestroy() method).
Note: jspInit(), _jspService() and jspDestroy() are the life cycle methods of JSP.

As depicted in the above diagram, JSP page is translated into Servlet by the help of

JSP translator. The JSP translator is a part of the web server which is responsible for
translating the JSP page into Servlet. After that, Servlet page is compiled by the

compiler and gets converted into the class file. Moreover, all the processes that happen
in Servlet are performed on JSP later like initialization, committing response to the

browser and destroy.

PAGE NO. 28
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
Creating a simple JSP Page
To create the first JSP page, write some HTML code as given below, and save it by .jsp

extension. We have saved this file as index.jsp. Put it in a folder and paste the folder in
the web-apps directory in apache tomcat to run the JSP page.
index.jsp

Let's see the simple example of JSP where we are using the scriptlet tag to put Java
code in the JSP page. We will learn scriptlet tag later.

1. <html>
2. <body>

3. <% out.print(2*5); %>


4. </body>

5. </html>
It will print 10 on the browser.
How to run a simple JSP Page?
Follow the following steps to execute this JSP page:
o Start the server
o Put the JSP file in a folder and deploy on the server
o Visit the browser by the URL http://localhost:portno/contextRoot/jspfile, for example,
http://localhost:8888/myapplication/index.jsp

Do I need to follow the directory structure to run a simple JSP?


No, there is no need of directory structure if you don't have class files or TLD files. For
example, put JSP files in a folder directly and deploy that folder. It will be running fine.

However, if you are using Bean class, Servlet or TLD file, the directory structure is
required.

The Directory structure of JSP


The directory structure of JSP page is same as Servlet. We contain the JSP page outside
the WEB-INF folder or in any directory.

PAGE NO. 29
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes

Extensible Markup Language - XML

XML stands for Extensible Markup Language. It is a text-based markup language


derived from Standard Generalized Markup Language (SGML).
XML tags identify the data and are used to store and organize the data, rather than
specifying how to display it like HTML tags, which are used to display the data. XML
is not going to replace HTML in the near future, but it introduces new possibilities by
adopting many successful features of HTML.
There are three important characteristics of XML that make it useful in a variety of
systems and solutions −
• XML is extensible − XML allows you to create your own self-descriptive
tags, or language, that suits your application.
• XML carries the data, does not present it − XML allows you to store
the data irrespective of how it will be presented.
• XML is a public standard − XML was developed by an organization
called the World Wide Web Consortium (W3C) and is available as an
open standard.
XML Usage
A short list of XML usage says it all −
• XML can work behind the scene to simplify the creation of HTML
documents for large web sites.

PAGE NO. 30
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
• XML can be used to exchange the information between organizations
and systems.
• XML can be used for offloading and reloading of databases.
• XML can be used to store and arrange the data, which can customize
your data handling needs.
• XML can easily be merged with style sheets to create almost any
desired output.
• Virtually, any type of data can be expressed as an XML document.
What is Markup?
XML is a markup language that defines set of rules for encoding documents in a
format that is both human-readable and machine-readable. So what exactly is a
markup language? Markup is information added to a document that enhances its
meaning in certain ways, in that it identifies the parts and how they relate to each
other. More specifically, a markup language is a set of symbols that can be placed in
the text of a document to demarcate and label the parts of that document.
Following example shows how XML markup looks, when embedded in a piece of text

<message>
<text>Hello, world!</text>
</message>

This snippet includes the markup symbols, or the tags such as


<message>...</message> and <text>... </text>. The tags <message> and
</message> mark the start and the end of the XML code fragment. The tags <text>
and </text> surround the text Hello, world!.

XML - Syntax
In this chapter, we will discuss the simple syntax rules to write an XML document.
Following is a complete XML document −

<?xml version = "1.0"?>


<contact-info>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</contact-info>

You can notice there are two kinds of information in the above example −
• Markup, like <contact-info>
• The text, or the character data, Tutorials Point and (040) 123-4567.
The following diagram depicts the syntax rules to write different types of markup
and text in an XML document.

PAGE NO. 31
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes

Let us see each component of the above diagram in detail.

XML Declaration
The XML document can optionally have an XML declaration. It is written as follows

<?xml version = "1.0" encoding = "UTF-8"?>


Where version is the XML version and encoding specifies the character encoding
used in the document.

Syntax Rules for XML Declaration


• The XML declaration is case sensitive and must begin with "<?xml>"
where "xml" is written in lower-case.
• If document contains XML declaration, then it strictly needs to be the
first statement of the XML document.
• The XML declaration strictly needs be the first statement in the XML
document.
• An HTTP protocol can override the value of encoding that you put in the
XML declaration.
Tags and Elements
An XML file is structured by several XML-elements, also called XML-nodes or XML-
tags. The names of XML-elements are enclosed in triangular brackets < > as shown
below.
<element>
Syntax Rules for Tags and Elements
Element Syntax − Each XML-element needs to be closed either with start or with
end elements as shown below −

PAGE NO. 32
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
<element>....</element>

or in simple-cases, just this way −

<element/>

XML References
References usually allow you to add or include additional text or markup in an XML
document. References always begin with the symbol "&" which is a reserved
character and end with the symbol ";". XML has two types of references −
• Entity References − An entity reference contains a name between the
start and the end delimiters. For example &amp; where amp is name.
The name refers to a predefined string of text and/or markup.
• Character References − These contain references, such as &#65;,
contains a hash mark (“#”) followed by a number. The number always
refers to the Unicode code of a character. In this case, 65 refers to
alphabet "A".
XML Text
The names of XML-elements and XML-attributes are case-sensitive, which means
the name of start and end elements need to be written in the same case. To avoid
character encoding problems, all XML files should be saved as Unicode UTF-8 or
UTF-16 files.
Whitespace characters like blanks, tabs and line-breaks between XML-elements and
between the XML-attributes will be ignored.
Some characters are reserved by the XML syntax itself. Hence, they cannot be used
directly. To use them, some replacement-entities are used, which are listed below −
Not Allowed Character Replacement Entity Character Description

< &lt; less than

> &gt; greater than

& &amp; ampersand

' &apos; apostrophe

" &quot; quotation mark

XML - DTDs
The XML Document Type Declaration, commonly known as DTD, is a way to describe
XML language precisely. DTDs check vocabulary and validity of the structure of XML
documents against grammatical rules of appropriate XML language.

PAGE NO. 33
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
An XML DTD can be either specified inside the document, or it can be kept in a
separate document and then liked separately.

Syntax
Basic syntax of a DTD is as follows −

<!DOCTYPE element DTD identifier


[
declaration1
declaration2
........
]>

In the above syntax,


• The DTD starts with <!DOCTYPE delimiter.
• An element tells the parser to parse the document from the specified
root element.
• DTD identifier is an identifier for the document type definition, which
may be the path to a file on the system or URL to a file on the internet.
If the DTD is pointing to external path, it is called External Subset.
• The square brackets [ ] enclose an optional list of entity declarations
called Internal Subset.
Internal DTD
A DTD is referred to as an internal DTD if elements are declared within the XML files.
To refer it as internal DTD, standalone attribute in XML declaration must be set
to yes. This means, the declaration works independent of an external source.

Syntax
<!DOCTYPE root-element [element-declarations]>
where root-element is the name of root element and element-declarations is where
you declare the elements.

Example
Following is a simple example of internal DTD −

<?xml version = "1.0" encoding = "UTF-8" standalone = "yes" ?>


<!DOCTYPE address [
<!ELEMENT address (name,company,phone)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
]>

<address>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</address>

PAGE NO. 34
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
External DTD
In external DTD elements are declared outside the XML file. They are accessed by
specifying the system attributes which may be either the legal .dtd file or a valid URL.
To refer it as external DTD, standalone attribute in the XML declaration must be set
as no. This means, declaration includes information from the external source.
Syntax
Following is the syntax for external DTD −
<!DOCTYPE root-element SYSTEM "file-name">
where file-name is the file with .dtd extension.
Example
The following example shows external DTD usage −
<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?>
<!DOCTYPE address SYSTEM "address.dtd">
<address>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</address>
The content of the DTD file address.dtd is as shown −
<!ELEMENT address (name,company,phone)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

XML - Schemas
XML Schema is commonly known as XML Schema Definition (XSD). It is used to
describe and validate the structure and the content of XML data. XML schema defines
the elements, attributes and data types. Schema element supports Namespaces. It is
similar to a database schema that describes the data in a database.
Syntax
You need to declare a schema in your XML document as follows −
Example
The following example shows how to use schema −
<?xml version = "1.0" encoding = "UTF-8"?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
<xs:element name = "contact">
<xs:complexType>
<xs:sequence>
<xs:element name = "name" type = "xs:string" />
<xs:element name = "company" type = "xs:string" />
<xs:element name = "phone" type = "xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

PAGE NO. 35
M. Gnanasekaran, MCA., M.Phil., SET., TVKGAC-TVR DT – Unit_II Notes
The basic idea behind XML Schemas is that they describe the legitimate format that
an XML document can take.

Elements
As we saw in the XML - Elements chapter, elements are the building blocks of XML
document. An element can be defined within an XSD as follows −

<xs:element name = "x" type = "y"/>


Definition Types
You can define XML schema elements in the following ways −

Simple Type
Simple type element is used only in the context of the text. Some of the predefined
simple types are: xs:integer, xs:boolean, xs:string, xs:date. For example −

<xs:element name = "phone_number" type = "xs:int" />


Complex Type
A complex type is a container for other element definitions. This allows you to specify
which child elements an element can contain and to provide some structure within
your XML documents. For example −

<xs:element name = "Address">


<xs:complexType>
<xs:sequence>
<xs:element name = "name" type = "xs:string" />
<xs:element name = "company" type = "xs:string" />
<xs:element name = "phone" type = "xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>

In the above example, Address element consists of child elements. This is a container
for other <xs:element> definitions, that allows to build a simple hierarchy of
elements in the XML document.

PAGE NO. 36

You might also like