1 Introduction to Distributed Application Development

Pravin Jain

epgp books

 

Introduction to the Paper

 

This paper has been divided into several modules. We have around 36 modules. In this module, we will be talking about the introduction of the paper. What are the various modules which we have? because this is DAD, its all going to be based on a client-server paradigm. I will also talk about the client-server paradigm.

 

What is Distributed Application Development?

 

It is about developing applications whose components have been divided into several parts. Rather than having all the facilities available in the particular application, being available in a single place as a single executable or something, Rather than having 1 such heavy-weight thing, we would have our application divided into several tiers(n-tiers). What is the role of each and every tier? How they interact? how the various things would perform? What are the various components?

 

There is one aspect which is of the interface. As far as the interfacing is concerned, the interface would normally be a web interface. Most of the modules are concentrating on that web-interface. We have chosen the Java technology for demonstrating the various aspects of Distributed Application Development, but it is not the only way.

 

There are various other technologies available. Java is one of the most common technology which is openly available and more popular. When it is Distributed Application Development, it not just one particular technology which can be used. Other options are also available.

 

Client Server paradigm

 

What do we understand by the client server paradigm?

If you look at the real world also, what is a server? or what is a client?

 

Any kind of service being provide by someone, he is a server and we have clients who utilize the service. There is going to be communication involved in all these. There is going to be communication between two seperate components. One of the components, the one who is giving service just has to wait and listen and he is not the initiator of the communication. The initiator of the communication is always going to be the client.

 

Even if someone has developed a Java class, the methods which are in the Java class are used by someone. That is being used by some other developer. That particular application which makes use of or invokes a method. Oh even that is a client server. There is someone who initiated and invokes a method and this component here is providing a method. this all happens within a thread. If this would be separated out and done by separate threads, it would be more like a client-server.

 

Browser is also a client interacting with some web server

 

Let us also have an overview of what all modules we are having in this paper. The kind of flow that we have over all these modules.

Overview of the Modules

 

What we have done in this particular paper is , we have initially started with a module on networking. Networking is mainly about how to communication between two processes which are on two different hosts.

 

We do have inter-process communication which happens between processes within the same machine/host. Even that is also client-server paradigm, because there is someone who is making service available. There is interaction which is done by another component. The interaction initiated by someone, that is a client. The one with whom the interaction is actually taking place, that is a server.

 

We have to interact with someone to get some information, so the other person is the service provider and we are the client if we are asking for something. We have one particular host having a particular process running and we have another host form where we have an application which would like to interact with that other process. The interaction with that process is by giving some request and getting some response.

 

Networking

 

The second module is on Networking where we will learn TCP/IP connection and communication. How to create TCP/IP connection. How two processes can interact over TCP/IP connection. One more thing here, Most of our concentration in all these modules is actually on writing more on the server side, there are a few things here which are also for the client side.

 

We will be using the java.net package, Socket, ServerSocket, these are the basic classes. We will talk about these in the second module..

 

Multi-threading and concurrency

 

The third module is about multithreading. in this case, the server wont be giving service to one client at a time. In second module , we develop an EchoServer. In third module, we will make that EchoServer such that even if there are multiple clients asking for service simultaneously, it should still be able to give service to all of them. So, for this on server side, we need multi-threading. Third Module is a demonstration of how to develop a multi-threaded network server. So, whatever server we develop in second module, in third module we make it multi-threaded.

 

The concurrency aspect is managed by the developer who is writing the server. But from Java 5 onwards we have some more mechnism, where the concurrecy aspect is handled independent of what is to be done. So we have APIs added in Java 5 called concurrency API. Fourth module is about using those kind of APIs and improving upon the code developed in third module. It demonstrates how we can control concurrency, in an existing Java application which was simply using multi-threading.

 

Remote Method Invocation

 

As was mentioned earlier, if someone is invoking a method on an object, it is also a client-server paradigm. if we are using java technology, we are more close to using Object-oriented way of solving problems. So we design classes and in classes we have got methods.

 

The fifth module is about RMI. So RMI is actually about how do we create objects on which method invocation can be done from a remote place. So developing such kind of objects. RMI is actually a Java technology but it would help you to create components for which method invocation can be done by any client from any place. Such components will be created. So that is what will be covered in fifth module.

 

To demonstrate the RMI based development, a simple ChatServer may be developed.

 

In the sixth module will be developing the server side of the chat server. It demonstrated how to develop a simple chat server. We have the seventh module which would actually be talking about developing the client side of the chat server application.So we can have a working chat server application there.

 

JDBC

 

Another very important type of service that we require. we may have the requirement of persisting the data. we have lots of data that needs to be saved. If we have objects, those objects need to be persisted. So for the purpose of persistence, one of the things which is very commonly used is the databases.

 

So we have database services, we have lots of databases. Different kinds of databases can be there. What we have in Java is we have a standard way of using databases.The standardization which was earlier available to the programmers of C in the form of ODBC. Similar to that ODBC, for Java programmers, we have got JDBC. We have got the JDBC APIs available as part of java.sql package. We have two modules here. Eighth and Ninth Modules would cover about the JDBC APIs.

 

In these modules we will talk about how to make a connection with the database in a standard way. So any standard Java application should be able to make connection to any kind of database, provided their JDBC drivers are available.

 

HTTP

 

The tenth and eleventh modules will be about understanding the HTTP protocol. The tenth module explains exactly what HTTP protocol is, and the format of the HTTP protocol, the format of the request of the HTTP, format of the response of the HTTP. We would understand that in the tenth module.

 

In the eleventh Module we talk about what is there in Java APIs for HTTP protocol, how anyone can be a client to an HTtp server. Eleventh module is actually about the HTTP client application.

 

We have many other popular protocols which have things being managed in terms of resources..We have a URL to represent the resource. The resource is nothing but something which gives us content. How do we get a content for a given URL.

 

By becoming a client, we can download content form any kind of a server, by using its URL.

 

Applet

 

The twelfth and thirteenth modules talk about Applet. Twelfth module also introduces the concept of a container. Applet used to be a very important component in Java for the client side for the web application. Now we have lot many other things which have replaced applets. How the applet was working, is an important concept that we introduce while talking about the applet and the life-cycle.

 

The concept of a container and a component. We have seen that applets are something which would work inside a browser. What exactly is the relation between the browser and the Applet. The Applet is being managed by the browser. How the browser would be managing it, the exact kind of interactions. The browser is actually on the client side but the server component the class file is stored on the server side. so it is actually brought into the client’s browser and working inside the client’s browser.

 

This aspect has been brought out in twelfth module. The thirteenth Module 13 is more about the rest of the Applet related APIs. In the twelfth module we would be talking about the Applet’s life-cycle. How the component which is our Applet here, is managed within the container. The component would have a life-cycle because the creation and all of those aspects of that component is actually done by a container. It is the browser who creates the objects of applets. and interacts with it to let it know things happening within the container. So that is the life-cycle of Applet and then we have various things, which the applet should then be able to interact with the browser and get help from the browser to do certain operations available in the browser. The container is giving it some environment, how that environment is made available to the component. The component interacting with the container, container interating with the component.

 

Java EE

 

There are so many aspects in developing a Distributed Application. In this paper we mainly concentrate on web applications but there are so many other things which are requirements of an Enterprise Applications. Enterprise applications are always Distributed Applications. What are the various components which are needed in enterprise applications. We have Java enterprise edition, everything here is in terms of specifications. The fourteenth module gives an overview of Java EE. What are the various requirements of the enterprise applications? There are common requirements of enterprise applications and these requirements have nothing to do with the domain for which the application is developed. We have common problems across all enterprise applications. and therefore all enterprise applications need some common infrastructure. So we don’t have to develop that infrastructure every time. That is where we have the concept of an application server which is used for our applications.

 

Enterprise applications would normally work on an application server. The developer doesn’t create the infrastructure. he develops the components, just like the applet was the component for the container. So we have lots of different kinds of containers to give different types of services. we just need to create those different smaller smaller components and its more about deploying and configuring them on the server side. The fourteenth to gives an overview of all those things.

 

Servlet Containers

 

In the fifteenth module talk about the web application. What is there in a web application. There are the Servlet specifications which are useful for a web application. The web application structure is there if we are using Java based components.

 

In Servlet specification there is a specific structure on how your web applications must be managed. We have some kind of a very good directory structure to manage all the components, all the resources which are to be part of web application So the definition, structure of web application, there is some XML file called web.xml, which is the deployment descriptor, what goes in the deployment descriptor, how it would be interpreted, there are various things in web.xml. how they are going to be interpreted by the container. all these aspects are covered in the fifteenth module.

 

Servlet Life-cycle

 

In the sixteenth module we talk about very basic component in the servlet specification. it is the Servlet component.

 

First we introduce the Servlet interface where we talk about the life-cycle of the Servlet. It talks in details about the life-cycle of Servlet. when a Servlet starts, it is going to address a particular resource, its going to address a particular URL.

 

When the Servlet starts it finds in order to give the service, there are certain resources which it is dependent upon and those resources are not yet up, even then what should it be doing? It is not that we get down to a Servlet and that Servlet gives an error. The container could be informed about it and the container at its own level could take care of giving the proper responses to the client, in case this particular Servlet component is down. We have a detailing on the life cycle methods. There are actually three life cycle methods. all these detailing is done in sixteenth module.

 

Servlet APIs

 

In the seventeenth and eighteenth modules, we go on to look at other components of servlet specifications. In servlet specification, we have components which the application developer would create, we have components which are going to be available to the application developer. As far as object creation is concerned, it is going to be entirely done by the container. All objects are managed by the container.

 

So we have only few components which the application developer creates or he defines. Rather, he defines Servlet and other components which we will cover in other subsequent modules. but what is going to be available to this particular servlet, he is going to be made available, configuration information by using ServletConfig. he is going to be made available the component for interaction with the container. How does he interact with the container and know about the entire web application? He wants to use other components in the web application or he wants to dispatch his request somewhere. So we have various kinds of components. Its a huge API. we have some basic API that has been covered in seventeenth module. we have eighteenth module looking at some more components. So, modules seventeen and eighteen gives us lot of information related to the Servlet API.

 

Servlet-Http specific APIs

 

The servlet specification is very general. its actually divided into two parts. We have a very general part of the Servlet specification, which we would be applicable to any protocol. for eg. we even have Servlet for SIP protocol also. It is not only about HTTP protocol, but most commonly it would be the HTTP protocol.

 

We first look at the API from generic point of view. So, there we have Servlet and we even talk about a class called GenericServlet and then later we have the eighteenth module which are specific to HTTP. So we have the nine module which is the HTTP specific API. We have something like the HttpServlet

 

In generic form we had only Servlet and GenericServlet but then we have HttpServlet. Here it uses HttpServletRequest, HttpServletResponse. Those are the interfaces which we will come across when we look at HTTP specific API. These are http specific components which any servlet specification will have to support. A Servlet Container may be supporting other protocols but this is something which is must. So any Servlet Container has to have this.

 

Then we have the twentieth module which covers things like cookies and sessions.

 

Filters and Listeners

 

Then we have the twenty first and the twenty second modules which talk about Filters and Listeners.

 

Servlet is not the only kind of components that the application developer creates. An application developer has certain requirements of using something like interceptor whenever a request comes. So, we have something called a Filter in the twenty first module, and then the twenty second module would be talking about Listeners.

 

Listeners are nothing but something like event dispatcher, event handlers. We have various events taking place within the container, or even at the start of the application we would like to do certain things. So we have those event classes. Similar to classes from the classical event delegation model being used here.

 

We have subclasses of java.util.EventObject class and we have Listeners which extend from java.util.EventListener. so all those things are there and we have the Listeners being discussed in the twenty second module.

 

JSP

 

After this, as far as the web is concerned, we move to the interface aspect. When we want to give someone a good web interface, we need to divide our job. Programmers would be good at processing part. Having a good design is a separate role of a webpage designer. who uses tags. so we have the next set of modules which talk on JSP it would normally be a task not of a programmer but of a web-page designer. In JSP we can have Java code entering within the tags. In JSP, within the tags, we can embed the Java code but, web designer is not a Java programmer, so he won’t understand Java programming. We cover those kind of elements which go in a JSP in the twenty third module.

 

We then subsequently move on to those things which are saying, do away with those kind of Java coding inside a JSP.

 

In the twenty fourth module we talk about JSP Directives, and then in later modules we also talk about what we call as tags.

 

There are those standard tags which are available for web page designer. Web page designers are used to tags. He gets all the functionality which he would normally require for having those use of the Java component which are going to be available in a JSP. These are the things, which are on the back-end side only, but the design appears on the front end.

 

JSPs are one kind of servlets only. but the one who writes JSP is a web page designer.

 

Custom Tags

 

After looking at the standard tags, we have something by which, even a programmer, if he wishes can create his own tags. We have modules thirty and thirty one which explains about how, if some programmer, if he wants make custom tags, to make it available to a webpage designer. how those custom tags can be created. How he can develop a library of those tags. how those tags can be deployed. That has been covered in the thirty first module..

 

JSTL and EL

 

Once having seen that we can have these kind of custom tags, there are certain tag libraries. There is some project from Apache which was a development of standard tag library called JSTL. That is very commonly being used with JSP. We have a standard set of tags so that we don’t keep on developing that commonly required ones. We discuss those standard tags, the JSTl. there is another things, a simplistic way of using objects within our JSP page.that is known as EL(expression language). so we cover JSTL and EL in thirty third and thirty fourth modules.

 

MVC – Model-View-Controller

 

We also have twenty sixth module talking about the architecture for web applications, which is the MVC architecture for developing web applications. We have a module to show you how different components can be managed. So that we have, for eg. the interface design, which should be in a JSP, but if we have any interaction from a client, he is making some query, he has to go to a database. that is something which a programmer will be doing. So we have Servlet doing that, we have controller, we have model classes. so dividing into MVC. JSP is the view part of MVC model. Model would be basic Java Beans components.

 

We discuss the Java Beans for creating those basic components in twenty fifth module. Having seen all the things about JSP,

 

Security

 

Another very important thing is security for any Distributed Application. We have thirty fifth module, talking about security in general. In this module we talk about security in general.

 

what is a key pair. what is a private, public key. what is meant by a certificate, what is a key store and the tools used for managing a key store. What is meant by signing something. A tool available in Java for signing the jar files. When we use Java technology, we have lot of jar files, most of things in these jar files are classes. So how do we have someone endorsing these. So we talk about security in general first.

 

We have thirty sixth module which would talk about security in web applications (nothing but a set of resources). Resources are URLs from client point of view. So certain URLs need to be protected. They have to be only available to authorized persons. So we have security for a web application. How authentication will be carried out.

 

These things can be done by some declarations in the deployment descriptor. so that is being covered in the thirty sixth module for web security.

 

That is how we go about in this particular paper.

you can view video on Introduction to Distributed Application Development

Suggested Reading:

  1. Core Java Volume 2 by Cay Horstmann & Gary Cornell, Ninth Edition, Pearson Education.
  2. The class of JAVA by Pravin Jain, Pearson Education.
  3. Beginning Java Networking by Alexander V Konstantinou and others, Wrox publication.
  4. Java RMI By William Grosso O’Rielly media
  5. Database programming with JDBC and Java by George Reese. O’Reilly Media
  6. Java Server Programming for Professionals by Ivan Bayross, Sharanam Shah, Cynhthia Bayross and Vaishali Shah Shroff Publishers and Distributros.
  7. Java EE 7 Essentials: Enterprise Developer Handbook by Arun Gupta, O’Reilly
  8. Core Servlets and Java Server Pages Volume 1 by Marty Hall & Larry Brown, Second Edition, Pearson Education.
  9. Core Servlets and Java Server Pages Volume 2 by Marty Hall & Larry Brown, Second Edition, Pearson Education.