JAVA Design Pattern

JAVA Design Pattern

The design patten is a vast subject, I will be giving you an head start here

Gang of Four – widely used design patterns

  1. Behavioral patterns
    1. Chain of responsibility
    2. Command
    3. Interpreter
    4. Iterator
    5. Mediator
    6. Memento
    7. Observer
    8. State
    9. Strategy
    10. Template method
    11. Visitor
  2. Creational patterns
    1. Abstract factory
    2. Builder
    3. Factory method
    4. Prototype
    5. Singleton
  3. Structural patterns
    1. Adapter
    2. Bridge
    3. Composite
    4. Decorator
    5. Facade
    6. Flyweight
    7. Proxy

Definition:- Common Problem and Common Solution for them, If you have data with problem and to tackle that you need to find problem pattern and propose solution pattern for that.

Note: No body owns the design pattern

Standard pattern are 23 those are listed above.

J2EE design pattern standardize by sun

EJB Patterns

  1. Intercepting Filter (apache mod rewrite)
  2. Composite View
  3. Front Controller
  4. Service to worker
  5. Business delegate
  6. Service Locater
  7. Transfer object assembler
  8. Facade



EJB cont

Entity Bean

An entity bean is representation of single row in a databases. Entity always be an heavy component. But the connectivity to database will be a transparent to developer. When you create a new entity bean automatically in database new row will be added.

ORM – Object Relational Mapping, row in a table will be one object in memory.

Stateless Session Bean can have pooled creation.

Statefull Session Bean can have cached creation.

But Entity bean can have either cache or pooled creation.

Whenever you need to work with processed or in other words process matters over data you should use session bean. But whenever you want to work with DATA or in other words DATA matters over process you should use entity beans.

Entity beans are heavy object because its a in memory object for database table. Where each instance of entity bean object refer to one record set in table or row in table.

Entity beans are of two types
Bean Managed Persistence
Container Managed Persistence

CMP Bean
Local Client
Remote Client

Favourite topic WSAD entity bean example 🙂 without writing a single line of code get the entity bean in place here we go

  1. Create new project EntityBean
  2. Create new Enterprise bean
  3. Select Type Entity bean
  4. Select CMP bean 2.0
  5. Bean detail select Remote & Local both the interfaces
  6. Select the project
  7. Run the Entity bean on server
  8. Configure new Test Server or run on existing server
  9. Create table and deploy entity bean
  10. Finish
  11. It will show success message, i.e. it will test the create and alter statement on newly created table.
  12. Select server client local
  13. Finish
  14. It will open Test Client
  15. Click on EntityExampleLocal
  16. Click on CMPLocal.findByPrimaryKey
  17. Enter value into and click invoke.

This how you will be testing tyour entity beans. Just now what we have seen is the Top to Bottom appoch, we have another approach which is Bottom to Top where in we will be having table already existing in and then will be creating the entity bean accordingly.  


-EJB can be accessed using servlet
-Entity Bean should not be remote
-Session Bean should not be local
-In entity bean you should not use primitive data-type.




Model= EJB
View= JSP
Controller = SERVLET

Why should we go for EJB?
Scalability (application should work same for 2 client and 2 million client.)
Should be catering to multiple request simulatanously.
Problem with the thread is Sycronization.
EJB CONTANER, will work on instance pooling and multiple instance.


to enable tansaction, first step is to make the autocomit off.
set autocommit flase applicable to the JVM where this property is set.

focus should be buisness logic, let transaction manage by somebody so this will be managed by CTM (container transaction management)

Web server & application server
Application server is super set of web server. In other words web server can be one component in application server.
Main diffrence will be application server is aware of its surroundings.

  1. Security
  2. Application control
  3. Infrastructural Capability

Application Server Main Properties

  1. Transaction management
  2. LDAP
  3. Persistance
  4. Threading
  5. Socket
  6. DBMS

Enterprise Level Application
EJB can be deploy only on Application Server. Used for scalable problems.

MESSAGE BEANS: asyncronous communication

If you need to generalizes something you make implementation and every one will write interface for it.

EJB distributed component need security any request comes in from cinet has to be checked.

EJB Contaner will decide whether to provide you access or not.

Per bean there will be one instance object.
Rule of thumb: One client one bean one instance will be always true.

Types of Bean

  1. Session Bean
    1. Stateless bean
    2. Statefull bean
  2. Enttyty Bean
    1. CMP – Container Managed Persistence
    2. BMP – Bean Managed Persistence
  3. Message Driven Bean (MBD) – Asyncronous beans

what to used and when to use

Dealing with process, Its a temporary or volatile.

Stateless-Session bean without any instance variables. i.e. processed are not dependent on each other. Example could be Controlling Mechenism

Statefull-Session bean with instance variable i.e.

Dealing with DBMS or Data

EJB FrameworkEJB framework Session Facade (Mean entry point.)

Creating session bean from Web Sphear Application Development.

EJB Module -> Project -> EJB -> Create 2.0 EJB -> Project Name -> Module Deps -> Finish

  1. newInstance()
  2. ejbCreate
  3. setSessionContext


Reflection & Retropection
Runtime can find out class and charachterstics

Call back method
Calles when an event occurs.

Thoughts on java

Java in not 100% OO?
1) Static classes, does not require instance to acces its charachterstics.
2) Reperesantation of real world entity without charachterstic is not possible. But we can create java class without any class variables.

Import Definations

Real world entity properties create class.

Coupling and Cohesion Software Engineering.




Client/server is dead. That’s the buzz now that newer Internet-based technologies are flourishing. But those new technologies are merely the natural evolution of earlier approaches, implemented with newer, more open protocols and designed to provide greater scalability, manageability, and diversity.

Middleware is computer software that connects software components or applications. It is used most often to support complex, distributed applications. It includes web servers, application servers, content management systems, and similar tools that support application development and delivery. Middleware is especially integral to modern information technology based on XML, SOAP, Web services, and service-oriented architecture.

Types of middleware

  • Remote Procedure Call (RPCs) — Client makes calls to procedures running on remote systems. Can be asynchronous or synchronous.
  • Message Oriented Middleware (MOM) — Messages sent to the client are collected and stored until they are acted upon, while the client continues with other processing.
  • Object Request Broker (ORB) — This type of middleware makes it possible for applications to send objects and request services in an object-oriented system.
  • SQL-oriented Data Access — middleware between applications and database servers.
  • Other sources include these additional classifications:
    • Transaction processing (TP) monitors — Provides tools and an environment for developing and deploying distributed applications.
    • Application servers — software installed on a computer to facilitate the serving (running) of other applications.
    • Enterprise Service Bus — An abstraction layer on top of an Enterprise Messaging System.