Showing posts with label Design. Show all posts
Showing posts with label Design. Show all posts

Tuesday, July 22, 2014

JSP:The Lifecycle

A JSP page services requests as a servlet. So, the life cycle of JSP are determined by Java Servlet technology.
There are following steps followed by JSP
1.Translation and Compilation
2.Initialization
3.Execution
4.Destruction
Translation and Compilation
When a browser asks for a JSP, the web container first checks to see whether the JSP page's servlet is older than the JSP page. If the servlet is older, the web container translates the JSP page into a servlet class and compiles the class. During development, one of the advantages of JSP pages over servlets is that the build process is performed automatically.During the translation phase each type of data (Html and JSP elements) in a JSP page is treated differently. Both the translation and the compilation phases can yield errors that are observed only when the page is requested for the first time. If an error is encountered during either phase, the servers will return JasperException and a message that includes the name of the JSP page and the line where the error occurred.
Initialization
After the page has been translated and compiled, container loads JSP page’s servlet class and instantiates an instance of the servlet class by calling jspInit method.
Execution
Whenever a browser requests a JSP and the page has been loaded and initialized, the web container invokes the _jspService () method in the JSP.
The _jspService () method takes an HttpServletRequest and an HttpServletResponse as its parameter. The _jspService () method of a JSP is invoked once per a request and is responsible for generating the response for that request. We can control various JSP page execution parameters by using page directive. When a JSP page is executed, output written to the response object is automatically buffered. We can set the size of the buffer using the following page directive:
<%@ page buffer="none|xxxkb" %>
A larger buffer allows more content to be written before anything is actually sent back to the client, thus providing the JSP page with more time to set appropriate status codes and headers or to forward to another web resource. A smaller buffer decreases server memory load and allows the client to start receiving data more quickly.
Destruction
The destruction phase of the JSP life cycle represents when a JSP is being removed from use by a container. If the container needs to remove the JSP page's servlet, it calls the jspDestroy method.

JSP:An Architecture

JSP Architecture
Web browser directly accesses the JSP page of web container. The JSP pages interact with the web container’s JavaBeans which represent the application model. When client sends request from a JSP page, the response is sent back to the client depending on the requests which are invoked by the client request. If response requires accessing the database, the JSP page uses JavaBeans to get data from the database.

Tuesday, August 28, 2012

JMS

Introduction


Message and messaging:
In general, message is an object whose existence is useful until used and messaging is a way through which message is used.
Technically, messaging is a method or way of communication between two or more applications. We can say that it is a peer to peer facility where a client send message to and receive message from, any other client. Each client connects to a messaging agent that provides facilities for creating, sending, receiving, and reading messages. Messaging enables loosely coupled architecture. In loosely coupled, the sender and receiver needs not be available at the same time in order to communicate. Sender and receiver don’t need to know anything about each other. They need to know the message format and destination to be used.

Sunday, August 26, 2012

JDBC

Introduction


JDBC is an API that helps java programmer to write java program to connect to a database, retrieve the data from form the database and perform various actions on the data in the java program.

Process of Java program to connect database through JDBC

Java program calls JDBC library.JDBC loads driver and driver talks to database.
The various classes used by java program to connect database in various steps of JDBC program are in following figure.


The following steps used by java program to connect to database using JDBC:


Registering the driver A database driver is a collection of classes and interfaces written according to JDBC API.Since there are several drivers available in the market, we should first decide the driver that would be used for communication with the database server in a java program.

Connecting to database
We establish a connection with the help of driver selected in prev. step.

Preparing SQL statements
We create SQL statement using any of the interfaces like Statement, Preparedstatement and CallableStatement available in Java.sql package.

Execute the SQL statements on the database
We use execute (), executeQuery () and executeUpdate () of statement interface.

Retrieving the results
The result obtained by executing the SQL statement can be stored in an object with the help of interfaces like ResultSet, ResultSetMetaData etc.

Closing the connection
We should close the connection between java program and database by using close() method.

Types of JDBC Driver

There are four types of java driver
Type 1: JDBC-ODBC Bridge Driver
This driver receives any JDBC calls and sends to ODBC driver. ODBC driver understands these calls and communicate with the database library.


Type 2: Native API-Partly Java Driver
It converts JDBC calls into database specific calls with the help of vendor database library. It communicates directly with the database server. So need of some binary code should be present in client machine.

Type 3: Net Protocol Pure Java Driver

It follows a three tier architecture where JDBC requests are passed through the network to a middle tier server. The middle tier server translates the request into database specific library and sends into the database server. The database server executes the request and gives back the results.
Type 4: Native Protocol Pure Java Driver

It converts JDBC calls into vendor specific database management system protocol so that client application communicates directly with the database server. This is completely implemented in Java to achieve platform independent.




Saturday, August 25, 2012

JNDI Architecture

The JNDI is an API that provides a standard protocol for accessing and sharing any network resources and its file structure in internet/Intranet and supports accessing a variety of naming and directory services. The purpose of naming service is to associates names with objects and provides access to objects through mapping a unique id to each object and its name.


The ranges of objects in a naming system can from files in a file system and names located in Domain Name System records, to Enterprise JavaBeans components in an application server and user profiles in Lightweight Directory Access Protocol directory. If you want to use Java to write an application such as a network-enabled desktop, an application launcher, a search utility, a network management utility or anything that accesses objects in a naming system then JNDI is a good architecture for writing that application.

Architecture

The architecture of JNDI is like the JDBC architecture, in which both provide a standard protocol-independent API built on top of protocol-specific driver or provider implementations. It consists of the JNDI API and the JNDI SPI. The JNDI API allows Java applications to access a variety of naming and directory services. The JNDI SPI is designed to be used by arbitrary service providers including directory service providers. This enables a variety of directory and naming services to be plugged in transparently to the Java application which uses only the JNDI API.


EJB Architecture

Component Model
Component has become new trend nowadays in software engineering. Component is self contained element of software that can be controlled dynamically. The basic concepts behind components are to build applications from reusable units that can easily be distributed by interoperating according to a set of rules and regulation.

Java Beans: Component Architecture for Java.
Java beans are Java’s component model. It allows users to construct applications by piecing components together either programmatically or visually (or both).It has the ability to write applications quickly and easily by using a palette of components that can be assembled to form larger applications. It is right to say that any component you can imagine can be written as a JavaBean, and then plugged into an application. If you know how to write software in Java, you know how to use and create Beans The model is made up of architecture and an API (Application Programming Interface). Together, these elements provide a structure whereby components can be combined to create an application.

EJB Architecture
When a client sends a request to server through jsp, container sees that request is for servlet and then creates two objects HttpServletResponse and HttpServletRequest. The container finds the correct servlet and creates a thread for that request but before passes the request and response object to the servlet thread, it passes to filter chain to intercepts and process the request .The servlet is having no knowledge of filter. After filtering the request the container passes the request and response object to the servlet thread and calls the service () of servlet depending on the type of request. Depending on the request servlet container passes the request to EJB container. But client never calls any of its requests directly. So when client sends a request to EJB object through servlet EJB container generates two objects EJB object and Home object which manage the service like Security, Persistence etc. and delegate the request to the associated beans(session, entity and message driven) instances. Home object hides the actual location of EJB object. So client access only that EJB objects that are stored at different location by the home object. Depends on the beans request goes to database through JDBC and fetch response from database and sends to EJB objects and then response goes to particular servlet. Thread completes and converts the response object to HTTP Response and sends back to the filter chain and again filter chain process the response and response sends to the client, then delete the request and response object. Finally client accepts response from servlet through JSP.





Friday, August 17, 2012

Java EE Architecture

First of all, we will say J2EE is not a product. Rather it is specification that defines the standard for the development of multitier enterprise applications in Java.


Formation of Architecture

Whenever we think about client-server concept then immediately first thing come in picture that there is a client asks for a resource to server. Here at least two things can happen.
1. Server provides that particular resource to client and
2. Server is not able to find what client asked for.
But in both cases server has to respond and I am sure that you have seen ‘404 not found’ error whenever you have tried to open a page and server didn’t find that page.

Whenever server sends a response, it sends some types of content (set of instruction written in HTML) and through HTTP.HTML tells the browser how to represent the content sent by server to user.

When browser sends a request to server for server, the server hands the request not to servlet itself but to container in which servlet is deployed.

Now question is how container handles servlet? Let’s see.

When a client send a request to server container sees that request is for servlet and then creates two objects HttpServletResponse and HttpServletRequest. The container finds the correct servlet and creates a thread for that request but before passes the request and response object to the servlet thread, it passes to filter chain to intercepts and process the request .The servlet is having no knowledge of filter. After filtering the request the container passes the request and response object to the servlet thread and calls the service () of servlet depending on the type of request. Thread completes and converts the response object to HTTP Response and sends back to the filter chain and again filter chain process the response and response sends to the client, then delete the request and response object.

Note: Request filter can perform security checks, reformat the request header and body and audit or log request. Response filter can compress the response stream and creates a different response altogether.

JVM Architecture

JVM is the main part of Java architecture and is the part of JRE(Java Runtime Environment).It is a component of the Java system that interprets and executes in our class files.
Memory configuration by the JVM
Each instance of the JVM has one method area, one heap and one or more stacks -one for each thread. When JVM loads a class files, it puts its information in the method area. As the program runs, all objects instantiated are stored in the heap. The stack area is used to store activation records as a program runs.
 Contents of memory Block at runtime
The class loader performs three main functions of JVM, namely: loading, linking and initialization. The linking process consists of three sub-tasks,namely,verification,preparation and resolution.
                                                     Class loading processes
Class loading process
Loading means reading the class file for a type, parsing it to get its information, and storing the information in the method area.The end of the loading process is the creation of an instance of java.lang.Class for the loaded type. The purpose is to give access to some of the information captured in the method area for the type, to the programmer.
The next process handled by the class loader is Linking. This involves three sub-processes: 1.Verification,
2.Preparation and
3.Resolution
Verification is the process of ensuring that binary representation of a class is structurally correct.
Preparation is the process of allocating memory by JVM for the class (i.e static) variables and sets them to default initial values.



Sunday, August 12, 2012

Architecture

Java Architecture

Java is the foundation for virtually every type of network application and is the global standard for developing and delivering mobile applications, games, Web based content and enterprise software.

When we think about architecture of Java then at least three things come into picture:
1. Java programming language
2. Java Class files
3. Java Virtual Machine

Suppose we write a java program a.java using Java. After compilation compiler produces a.class which contains byte code instructions. These byte code instructions are given to JVM to understand that which processor used. After that JVM converts byte code into machine code that is compatible to processor which is used to write a.java.

                   
                                                    

Copyright © Codingnodes,2014.All Rights Reserved.