You are on page 1of 48


S.No 1. 2. 3. 4. 5. 6. 7. 8. Description Study of Multi-tier Software Environment Study of web servers/ web browser and tools for enterprise development and deployment Developing a package using rmi Simple jdbc connectivity using statement & prepared statement Simple servlet application Session management in servlet Developing a shopping cart package using servlet Creation of javabean component Page No 1 8 18 22 24 26 28 32

Creation of com component for simple 9. calculator using vb activex control 35

10. 11.

Develop a simple package using jsp Deploying ejb for simple arithmetic operation

41 42

EX. NO.: 01

Study of Multi-tier Software Environment

A tier is an abstract concept that defines a group of technologies that provides one or more services to its clients. In multi-tier architecture each tier contains services that include software object or DBMS. Multi-tier architecture is composed of clients, resources, components (service), and containers. Clients, Resources and Components A client refers to a program that requests a service from a component. A resource is anything a component needs to provide a service, and a component is part of tier that consists of a collection of classes or a program that performs a function to provide the service. A container is software that manages a component and provides a component with system services. The relationship between a container and a component is sometimes referred to as a contract, whose terms are governed by an application programming interface (API). An API defines rules a component must follow and the services a component will receive from the container. A container handles persistence, resource management, security, threading and other system-level services for components that are associated with the container. Components are responsible for implementation of business logic. It helps the programmer to focus on coding business rules into components without becoming concerned about lowlevel system services. The relationship between client, component and resource is shown below.

Request Container Reply






Normally large organizations employ multi-tier architecture because it is easy to build an application that is flexible, scalable and responsive to the expectation of clients. Considering an organization that groups its services as marketing tier, production tier, support tier and facility services tier. At the lowest level facility services contains variety of resources that include electricity, elevator, computer network, and telephone services. The next tier in the organization contains support resources like computer programming, accounting, counseling etc. Production tier has the resources necessary to produce products and services sold by the company. The highest tier consists of resources for product management and advertising. All the tiers should interact with each other for the proper functioning of the enterprise. This is similar to the tier structure in distributed systems. The tier relationship in an enterprise is given below.

Marketing tier

Product management


Production tier



Support tier



Facility tier




The advantages of the multi-tier architecture are: Forced separation of user interface logic and business logic. Business logic sits on small number of centralized machines (may be just one).

Easy to maintain, to manage, to scale, loosely coupled etc. Each tier is assigned a unique responsibility in a 3-tier system. Each tier is logically separated and loosely coupled from each other, and may be distributed.

The J2EE platform uses a multitiered distributed application model. Application logic is divided into components according to function, and the various application components that make up a J2EE application are installed on different machines depending on the tier in the multitiered J2EE environment to which the application component belongs. Figure 1-1 shows two multitiered J2EE applications divided into the tiers described in the following list. The J2EE application parts shown in Figure 1-1 are presented in J2EE Components.

Client-tier components run on the client machine. Web-tier components run on the J2EE server. Business-tier components run on the J2EE server. Enterprise information system (EIS)-tier software runs on the EIS server.

Although a J2EE application can consist of the three or four tiers shown in Figure 1-1, J2EE multitiered applications are generally considered to be three-tiered applications because they are distributed over three different locations: client machines, the J2EE server machine, and the database or legacy machines at the back end. Three-tiered applications that run in this way extend the standard two-tiered client and server model by placing a multithreaded application server between the client application and back-end storage.

Figure 1-1 Multi-tiered Applications

J2EE Components
J2EE applications are made up of components. A J2EE component is a self-contained functional software unit that is assembled into a J2EE application with its related classes and files and that communicates with other components. The J2EE specification defines the following J2EE components:

Application clients and applets are components that run on the client.

Java Servlet and JavaServer Pages (JSP ) technology components are Web components that run on the server. Enterprise JavaBeans (EJB ) components (enterprise beans) are business components that run on the server.

J2EE components are written in the Java programming language and are compiled in the same way as any program in the language. The difference between J2EE components and "standard" Java classes is that J2EE components are assembled into a J2EE application, verified to be well formed and in compliance with the J2EE specification, and deployed to production, where they are run and managed by the J2EE server.

J2EE Clients
A J2EE client can be a Web client or an application client.

Web Clients
A Web client consists of two parts: dynamic Web pages containing various types of markup language (HTML, XML, and so on), which are generated by Web components running in the Web tier, and a Web browser, which renders the pages received from the server. A Web client is sometimes called a thin client. Thin clients usually do not do things like query databases, execute complex business rules, or connect to legacy applications. When you use a thin client, heavyweight operations like these are off-loaded to enterprise beans executing on the J2EE server where they can leverage the security, speed, services, and reliability of J2EE server-side technologies.

A Web page received from the Web tier can include an embedded applet. An applet is a small client application written in the Java programming language that executes in the Java virtual machine installed in the Web browser. However, client systems will likely need the Java Plug-in and possibly a security policy file in order for the applet to successfully execute in the Web browser. Web components are the preferred API for creating a Web client program because no plugins or security policy files are needed on the client systems. Also, Web components enable cleaner and more modular application design because they provide a way to separate applications programming from Web page design. Personnel involved in Web page design thus do not need to understand Java programming language syntax to do their jobs.

Application Clients
A J2EE application client runs on a client machine and provides a way for users to handle tasks that require a richer user interface than can be provided by a markup language. It

typically has a graphical user interface (GUI) created from Swing or Abstract Window Toolkit (AWT) APIs, but a command-line interface is certainly possible. Application clients directly access enterprise beans running in the business tier. However, if application requirements warrant it, a J2EE application client can open an HTTP connection to establish communication with a servlet running in the Web tier.


Component Architecture

The server and client tiers might also include components based on the JavaBeans component architecture (JavaBeans component) to manage the data flow between an application client or applet and components running on the J2EE server or between server components and a database. JavaBeans components are not considered J2EE components by the J2EE specification. JavaBeans components have instance variables and get and set methods for accessing the data in the instance variables. JavaBeans components used in this way are typically simple in design and implementation, but should conform to the naming and design conventions outlined in the JavaBeans component architecture.

J2EE Server Communications

Figure 1-2 shows the various elements that can make up the client tier. The client communicates with the business tier running on the J2EE server either directly or, as in the case of a client running in a browser, by going through JSP pages or servlets running in the Web tiers. Your J2EE application uses a thin browser-based client or thick application client. In deciding which one to use, you should be aware of the trade-offs between keeping functionality on the client and close to the user (thick client) and off-loading as much functionality as possible to the server (thin client). The more functionality you off-load to the server, the easier it is to distribute, deploy, and manage the application; however, keeping more functionality on the client can make for a better perceived user experience.

Figure 1-2 Server Communications

Web Components

J2EE Web components can be either servlets or JSP pages. Servlets are Java programming language classes that dynamically process requests and construct responses. JSP pages are text-based documents that execute as servlets but allow a more natural approach to creating static content. Static HTML pages and applets are bundled with Web components during application assembly, but are not considered Web components by the J2EE specification. Server-side utility classes can also be bundled with Web components and, like HTML pages, are not considered Web components. Like the client tier and as shown in Figure 1-3, the Web tier might include a JavaBeans component to manage the user input and send that input to enterprise beans running in the business tier for processing.

Business Components
Business code, which is logic that solves or meets the needs of a particular business domain such as banking, retail, or finance, is handled by enterprise beans running in the business tier. Figure 1-4 shows how an enterprise bean receives data from client programs, processes it (if necessary), and sends it to the enterprise information system tier for storage. An enterprise bean also retrieves data from storage, processes it (if necessary), and sends it back to the client program.

Figure 1-3 Web Tier and J2EE Application

Figure 1-4 Business and EIS Tiers There are three kinds of enterprise beans: session beans, entity beans, and message-driven beans. A session bean represents a transient conversation with a client. When the client finishes executing, the session bean and its data are gone. In contrast, an entity bean represents persistent data stored in one row of a database table. If the client terminates or if the server shuts down, the underlying services ensure that the entity bean data is saved. A message-driven bean combines features of a session bean and a Java Message Service ("JMS") message listener, allowing a business component to receive JMS messages asynchronously. This tutorial describes entity beans and session beans. For information on message-driven beans,

Enterprise Information System Tier

The enterprise information system tier handles enterprise information system software and includes enterprise infrastructure systems such as enterprise resource planning (ERP), mainframe transaction processing, database systems, and other legacy information systems. J2EE application components might need access to enterprise information systems for database connectivity, for example.

EX. NO. :02


WEB BROWSER A web browser is a software application for retrieving, presenting, and traversing information resources on the World Wide Web. An information resource is identified by a Uniform Resource Identifier (URI) and may be a web page, image, video, or other piece of content. Hyperlinks present in resources enable users to easily navigate their browsers to related resources. Although browsers are primarily intended to access the World Wide Web, they can also be used to access information provided by Web servers in private networks or files in file systems. Some browsers can be also used to save information resources to file systems.

List of web browsers

Notable browsers :(In order of release)

Worldwide Web, February 26, 1991 Mosaic, April 22, 1993 Netscape Navigator and Netscape Communicator, October 13, 1994 Internet Explorer 1, August 16, 1995 Opera, 1996, see History of the Opera Internet suite Mozilla Navigator, June 5, 2002 Safari, January 7, 2003 Mozilla Firefox, November 9, 2004 Google Chrome, September 2, 2008

Browsers for the Java platform

Bitstream ThunderHawk BOLT Browser HotJava (discontinued) Lobo (formerly Warrior) Opera Mini 9

uZard Web X-Smiles (experimental) Flying saucer, a Java library for rendering XML, XHTML, and CSS 2.1 content. UCWEB

Web Page retrieval: The browser application retrieves or fetches code, usually written in HTML (HyperText Markup Language) and/or another language, from a web server, interprets this code, and renders (displays) it as a web page for you to view. In the majority of cases, user interaction is needed to tell the browser what web site or specific web page he or she would like to view. One way this is done is via the browser's address bar. The web address or URL (Uniform Resource Locator), that you type into the browser's address bar tells the browser where to obtain a page or pages from. For example, let's say that you typed the following URL into the browser's address bar: In this case, you're attempting to reach the Computing & Technology section of The browser looks at this particular URL in two main sections. The first is the protocol, which in the address shown is "http://". HTTP, which stands for HyperText Transfer Protocol, is the standard protocol used to request and transmit files on the Internet, mostly web pages and their respective components. Since the browser now knows that the protocol is HTTP, it knows how to interpret everything located to the right of the forward slashes. It now looks at "", which tells the browser the location of the web server it needs to retrieve the page or pages from. Next, once it reaches this web server, it retrieves the index page of the "/compute" directory. Once this page is retrieved by the browser, it is interpreted and rendered in the browser's main window for you to view. WEB SERVER A web server is a computer programs that delivers (serves) content, such as web pages, using the Hypertext Transfer Protocol (HTTP), over the World Wide Web. The term web server can also refer to the computer or virtual machine running the program. In large commercial deployments, a server computer running a web server can be rack-mounted with other servers to operate a web farm. A web server is a piece of software that enables a website to be viewed using HTTP. HTTP (HyperText Transfer Protocol) is the key protocol for the transfer of data on the web. You 10

know when you're using HTTP because the website URL begins with "http://" (for example, ""). Some high-powered computers are referred to as web servers as they have been built with web hosting in mind. But in most cases, when someone refers to a web server, they are referring to a piece of software that you install on a computer. Advantages There are many advantages to using a web server within your development environment. Of course, in a production hosting environment, a web server is essential. And, depending on your website, a web server could indeed be essential in your development environment. Here are some advantages of using a web server within your development environment:

Your local website behaves more like the live one. For example, you can configure directory security, test your custom error pages etc before committing them to the production environment. You can use server-side scripting languages such as PHP and ColdFusion. Allows you to standardize your coding. For example, you can use root-relative paths for your image references and hyperlinks (i.e. "/directory/image.gif"). In other words, your paths can represent the website structure, rather than the directory structure of your computer. Knowledge. The knowledge you gain from using your own web server will help you understand how it works in the live environment. This will most certainly help you when you need to communicate with your hosting provider - you'll be able to use terminology that makes it easier for them to understand your request/issue.

Viewing HTML Files with a Web Server When you view a web page via a web server, the URL begins with "http://". Also, the URL will consist of either an IP address or a domain name/host name. Here are some examples of what the URL could look like when viewing a web page via a web server: http://localhost

Web Servers Features There's a common set of features that you'll find on most web servers. Because web servers are built specifically to host websites, their features are typically focused around setting up and maintaining a website's hosting environment.


Most web servers have features that allow you to do the following:

Create one or more websites. Configure log file settings, including where the log files are saved, what data to include on the log files etc. (Log files can be used to analyze traffic etc) Configure website/directory security. For example, which user accounts are/aren't allowed viewing the website, which IP addresses are/arent, allowed to view the website etc. Create an FTP site. An FTP site allows users to transfer files to and from the site. Create virtual directories, and map them to physical directories Configure/nominate custom error pages. This allows you to build and display user friendly error messages on your website. For example, you can specify which page is displayed when a user tries to access a page that doesn't exist (i.e. a "404 error"). Specify default documents. Default documents are those that are displayed when no file name is specified. For example, if you open "http://localhost", which file should be displayed? This is typically "index.html" or similar but it doesn't need to be. You could nominate "index.cfm" if your website is using ColdFusion. You could also nominate a 2nd choice (in case there is no index.cfm file), and a 3rd choice, and so on.

How Web Servers Work : Whenever you view a web page on the internet, you are requesting that page from a web server. When you type a URL into your browser (for example, ""), your browser requests the page from the web server and the web server sends the page back:

The above diagram is a simplistic version of what occurs. Here's a more detailed version: 1. Your web browser first needs to know which IP address the website "" resolves to. If it doesn't already have this information stored in it's cache, it requests the information from one or more DNS servers (via the internet). The DNS server tells the browser which IP address the website is located at. Note that the IP address was assigned when the website was first created on the web server. 2. Now that the web browser knows which IP address the website is located at, it can request the full URL from the web server.


3. The web server responds by sending back the requested page. If the page doesn't exist (or another error occurs), it will send back the appropriate error message. 4. Your web browser receives the page and renders it as required. When referring to web browsers and web servers in this manner, we usually refer to them as a client (web browser) and a server (web server). Multiple Websites A web server can (and usually does) contain more than one website. In fact, many hosting companies host hundreds, or even thousands of websites on a single web server. Each website is usually assigned a unique IP address which distinguishes it from other websites on the same machine. This IP address is also what the DNS server uses to resolve the domain name. It is also possible to configure multiple websites without using different IP addresses using host headers and/or different ports. This can be useful in a development environment and is quite easy to do. Page Not Found If the requested page isn't found, the web server sends the appropriate error code/message back to the client. You can create user friendly error messages, then configure your web server to display that page instead of the usual error page. This can add a nice touch to your website. How many times have you (or even worse, your visitors) encountered a plain white page with some cryptic error message on it? Default Documents If you've ever created a website, you may have found that if you have an "index" file (index.html for example), you don't need to specify the name of the file. For example, the following URLs both load the same page: 1. 2. In this example, "index.cfm" is the default document. You can configure your web server so that any file name can be the default document. For example, you could configure your web server to use "index.cfm" in the event no filename has been specified, or if you use PHP, "index.php". You could even specify different default documents for different directories if you like.


SSL Certificates You can apply SSL certificates against a website via the web server. First you need to generate the certificate either by yourself (i.e. using a certificate generator), or by a Certificate Authority (CA). Then, once it has been generated, you apply it to your website via your web server. Applying an SSL certificate to a website is a straight forward task. Once you've applied an SSL certificate against a website, you can navigate it using HTTPS (as opposed to HTTP). HTTPS encrypts any data that is transferred over the internet. This reduces the possibility of some malicious person being able to read your users' sensitive information. Apache HTTP Server Apache HTTP Server (also referred to as simply "Apache") has, at the time of writing, been the most popular web server on the web since 1996. Apache is developed and maintained by the Apache Software Foundation, which consists of a decentralized team of developers. The software is produced under the Apache licence, which makes it free and open source. Apache is available for a range of operating systems, including Unix, Linux, Novell Netware, Windows, Mac OS X, Solaris, and FreeBSD. Microsoft Internet Information Services (IIS) IIS is, at the time of writing, the second most popular web server on the web. It is however, gaining market share, and if the current trend continues, it won't be long before it overtakes Apache. IIS comes as an optional component of most Windows operating systems. You can install IIS by using Add/Remove Windows Components from Add or Remove Programs in the Control Panel. Sun Java System Web Server Based on the Sun One Web Server, the Sun Java System Web Server is designed for medium to large business applications. Sun Java System Web Server is available for most operating systems. Tools for enterprise software Enterprise software, also known as enterprise application software (EAS), is software intended to solve an enterprise problem (rather than a departmental problem) and often written using an Enterprise Software Architecture. Due to the cost of building or buying what is often proprietary software, only large enterprises attempt to implement such enterprise software that models the entire business enterprise and is the core IT system of governing the enterprise and the core of communication within the enterprise.


As business enterprises have similar departments and systems in common, enterprise software is often available as a suite of programs that have attached enterprise development tools to customize the programs to the specific enterprise. Generally, these development tools are complex enterprise programming tools that require specialist capabilities. Enterprise-level application Enterprise level software is software which provides business logic support functionality for an enterprise, typically in commercial organizations, which aims to improve the enterprise's productivity and efficiency. Services provided by enterprise software are typically business-oriented tools such as online shopping and online payment processing, interactive product catalogue, automated billing systems, security, content management, CRM, ERP, Business Intelligence, HR Management, Manufacturing, EAI, Enterprise Forms Automation etc. Characteristics of enterprise software are performance, scalability, and robustness. Enterprise software typically has interfaces to other enterprise software (for example LDAP to directory services) and is centrally managed (a single admin page for example). Enterprise Application software Enterprise application software is application software that performs business functions such as order processing, procurement, production scheduling, customer information management, accounting, etc. It is typically hosted on servers and provides simultaneous services to a large number of users, typically over a computer network. This is in contrast to single-user application that execute on a user's personal computer and serve only one user at a time. :) Enterprise software developers Major organizations in the enterprise software field include IBM, HP, JBoss (Red Hat), SAP, Microsoft, Adobe Systems, Oracle Corporation, and Computer Associates but there are thousands of competing vendors. In addition, a great deal of enterprise software is now available through the free software movement, notably operating systems, web servers and databases. Many other types of enterprise software are also being introduced, such as application servers, portal servers, and even productivity software that is well suited for large-scale adoption by enterprises. While most open source software is available freely for use and further development, several companies provide enterprises with open source enterprise software for free and charge for software maintenance, modifications, support and additional functionality. Cross-platform RAD tools

Boa constructor is a cross-platform, wxPython based Python RAD IDE


Code: Blocks is a cross-platform C/C++ RAD IDE using wxWidgets; the latest developmental builds have a built-in form designer wxSmith, so it's similar to Embarcadero C++ Builder and Microsoft Visual C++/MFC now. HyperNext is a freeware cross-platform software development system for Mac OS X & Mac OS 9, and Microsoft Windows XP & Vista. It has many similarities with HyperCard and can compile to both stand alone applications and stacks for the cross-platform HyperNext Player. IBM Rational Business Developer Extension is a cross-platform, Rapid Application Development IDE for creating enterprise and web applications and services for Windows, Linux, Unix (Solaris, HPUX, AIX), System z and System i IBM Rational Application Developer is a cross-platform, Rapid Application Development IDE for creating enterprise and web applications and services for Windows, Linux and Unix (Solaris, HPUX, AIX) LANSA is a development environment for generating applications on multiple platforms. One of the main features of LANSA is its high level programming language, called RDML (Rapid Development and Maintenance Language). It is classified as a 4GL (4th generation language). LANSA-developed applications run on many systems including MS Windows, IBM i and Linux. Lazarus is a cross-platform IDE similar to Embarcadero Delphi. NetBeans is a cross-platform, RAD IDE for creating visual desktop, mobile, web, and SOA applications for Linux, Windows and Mac OS X. The IDE officially supports Java, Ruby, PHP, JavaScript and C/C++ programming languages. Squeak is an open-source, cross-platform Smalltalk system which can be used to develop applications for desktop, mobile, server-based, and web platforms. Squeak supports Windows, Linux, Mac OS X, Mac OS Classic, many flavors of Unix, and a handful of other operating systems. Squeak is the home of the Seaside RAD web app framework and multiple GUI toolkits, some of which allow the building of GUIs by drag and drop. Visual FoxPro With its local cursor engine, tight coupling between language and data, and powerful features, Visual FoxPro 9.0 is a great tool for building database solutions of all sizes. Its data-centric, object-oriented language offers developers a robust set of tools for building database applications for the desktop, client server environments, or the Web. Developers will have the necessary tools to manage datafrom organizing tables of information, running queries, and creating an integrated relational database management system (DBMS) to programming a fullydeveloped data management application for end users. VisualWorks is a cross-platform Smalltalk RAD for creating desktop, mobile, enterprise, and web-based applications for Windows, Linux, Mac OS X, Mac OS Classic, and a number of Unix systems. The system supports popular protocols and frameworks like ODBC, Seaside, and GemStone/S. Commercial and free noncommercial versions available.

Cloud Based RAD tools



Wavemaker is an open-source, visual, drag and drop development studio that runs in a browser and generates standard Java applications for deployment. Cloud version is available at [Cloud]. Zoho Office Suite

Desktop RAD Tools

C++Builder . Clarion is a data-centric Advanced Rapid Application Development (ARAD) tool featuring roundtrip code generation that preserves all of your own hand-written code while allowing you to re-generate your application as often as needed. It provides reusable metadata to quickly create "corporate quality" applications to manage business data Delphi . Microsoft Visual Basic .

Database RAD Tools

Base One Foundation Component Library (BFC) is a RAD framework for building .NET applications using SQL Server, Oracle, DB2, Sybase, and MySQLdatabases. Clarion is a data-centric Advanced Rapid Application Development (ARAD) tool featuring roundtrip code generation that preserves all of your own hand-written code while allowing you to re-generate your application as often as needed. It provides reusable metadata to quickly create "corporate quality" applications to manage business data IBM Rational Application Developer supports database application development for IBM DB2, IBM Informix, Oracle database, Microsoft SQL Server and other JDBC compliant relational databases

Embedded Control RAD Tools

VisSim is a block diagram language for model based embedded system development LabVIEW is a graphical programming language that allows you to program embedded off-the-shelf systems, FPGAs, custom designs

Web Based RAD Tools

ASPRunner\PHPRunner is a data model based code generator that can generate either PHP or ASP Web pages based on the data model relationships, it also includes WYSIWYG web page customization. Caspio is a platform-as-a-service framework that uses wizards instead of coding for RAD. MyEclipse for Spring is a RAD tool for developing Java-based Spring applications. It runs within the MyEclipse IDE.


Oracle Application Development Framework uses Oracle's JDeveloper a FREE IDE that supports ADF's J2EE based framework. Visual WebGui (VWG) is an open-source rapid application development (RAD) framework for AJAX & Silverlight GUIs. The platform presents a new approach to applying desktop usability to the web by viewing it as an extension to a desktop rather than web Sculpture is a 100% free .NET based Platform for designing and delivering cross platform web applications.

Components based on RAD paradigm

Add-in Express Visual RAD tool for developing COM add-ins, smart tags, RTD servers and Excel user defined functions in Visual Studio .NET and Delphi. Panther is a cross-platform (Windows, UNIX, Linux; TUI, GUI, Web), crossdatabase RAD toolset for development of n-tier component based database oriented applications. It builds native components employing the same visual paradigm used for client screens. Editions for middleware from IBM, BEA and Microsoft exist (and can be combined).


Ex. No:03 AIM


To develop a package for string operation in java using RMI. DESCRIPTION Remote Method Invocation (RMI) applications comprise the client and server programs. The server application creates remote objects and facilitates their access through their references. These references are registered in the RMI registry. A client application invokes the remote methods by fetching the reference of the remote object from the registry. The remote invocation has the same semantics as the local invocations. Java RMI thus facilitates invocations on methods exposed by the interfaces offered by the remote objects. Java RMI is specifically meant for Java programming language. RMI functionality is performed using the following layers 1. Stub and Skeleton Layer: This layer marshals and unmarshals the data using Java objects serialization format. 2. Remote Reference Layer: This layer takes care of allocation of buffers and carrying out the invocation process. 3. Transport Layer: This layer is responsible for setting up connections as well as managing , monitoring and listening incoming calls. SOFTWARE REQUIREMENTS java PROCEDURE The sequence of steps to be followed while executing an RMI application is listed as follows: 1. Creation of Remote Interface: An interface exposes the services offered by the remote object to the client. It does not implement these methods. Remote interfaces shoult


extend java.rmi.Remote interface. All the methods defined in thisinterface should throw java.rmi.RemoteException. interface s1 extends Remote { public int len(String msg) throws RemoteException; public String con(String msg1,String mag2) throws RemoteException; public String up(String msg3) throws RemoteException; public String reverse(String msg4) throws RemoteException; } 2. Creation of the Remote Class to implement the Interface: This implementation class implements the remote interface and extends java.rmi.UnicastRemoteObject. 3. Creating a Remote Instance in a server Class: The RMI server creates an instance of implemantation class and registers it in the RMI registry using rebind() method. It informs RMI registry that iobject is available as localhost in the RMI registry. Naming.rebind("localhost",i); The following is a listing of the server class code: import java.rmi.*; import java.rmi.server.*; interface s1 extends Remote { public int len(String msg) throws RemoteException; public String con(String msg1,String mag2) throws RemoteException; public String up(String msg3) throws RemoteException; public String reverse(String msg4) throws RemoteException; } class Str extends UnicastRemoteObject implements s1 { public Str() throws RemoteException { System.out.println("hello server is ready"); } public int len(String msg) throws RemoteException { return msg.length(); } public String con(String msg1,String msg2) throws RemoteException { return msg1.concat(msg2); } public String up(String msg3) throws RemoteException { return msg3.toUpperCase(); } public String reverse(String msg4) throws RemoteException StringBuffer buffer = new StringBuffer(msg4); return new String(buffer.reverse()); } } public class SerString { public static void main(String[] args) throws RemoteException { try { s1 i = new Str(); Naming.rebind("localhost",i); System.out.println("hello server is ready"); } catch(Exception e) { System.out.println("server failed:"+e); } } }


4. Writing a client to connect to the server: The client (CliString) uses Naming.lookup() to get the reference of the remote object. This reference is then used to invoke the remote methods: import java.rmi.*; import java.rmi.server.*; import*; import java.lang.*; public class CliString { public static void main(String[] argv) throws IOException { try { s1 hello =(s1)Naming.lookup("localhost"); System.out.println("length is: " + hello.len("hai")); System.out.println("concatenated as: " + hello.con("hello","hai")); System.out.println("In UPPERCASE as: " + hello.up("hai")); System.out.println("reverse as: " + hello.reverse("hai")); } catch(Exception e) { System.out.println("hello client exception:"+e); } } } 5. Process of Compilation: All java source files are compiled using javac compiler as follows: javac *.java 6. Creating stub files using RMI compiler(rmic): RMI compiler is run on the implemantation class using the command rmic Str. It generates the skeleton and stub files, Str_Skel.class and Str_Stub.class respectively in the same folder. 7. Start the RMI registry: Using start rmiregistry command, the RMI registry is started. 8. Starting RMI server Program: The server is started using java SerString command. This server creates an instance of base and makes it known to the rmi server as localhost using Naming.rebind() method. 9. Executing the client application: The client program is started using java CliString. It fetches the reference to localhost from the RMI registry. Using this reference, the client invokes methods declared in the interface.


Build.xml: (For running it in NetBeans) <target name="startRMI" depends="init"> <exec executable="rmiregistry" dir="${build.classes.dir}" /> </target> OUTPUT Server


RESULT Thus the package for string operation has been created and tested in java using RMI.


Ex. No: 04


AIM: To create a JDBC connectivity using Statement and prepared statement. PROCEDURE 1. Create a DNS with the name test by choosing the provider Microsoft ODBC for oracle. 2. Embed the SQL statements, like create, insert, select in the java program. 3. This program on execution creates a table called demo and inserts values to that table in SQL. PROGRAM import*; import java.sql.*; class jdbc { public static void main(String arg[]) throws Exception { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:test","scott","tiger"); //String str="insert into demo123 values(?,?)"; //PreparedStatement pt=con.prepareStatement(str); //pt.setInt(1,2); //pt.setString(2, "sathiya"); //ResultSet rs=pt.executeQuery(); Statement stmt=con.createStatement(); stmt.executeUpdate("create table demo123(no number(5),name varchar2(10))"); stmt.executeUpdate("insert into demo123 values(1,'abhiject')"); stmt.executeUpdate("insert into demo123 values(12,'dhanaraj')"); stmt.executeUpdate("insert into demo123 values(21,'krishna')"); stmt.executeUpdate("insert into demo123 values(25,'nandu')"); ResultSet rs=stmt.executeQuery("select * from demo123 where no=1"); System.out.println("number\tname");


while( { String id=rs.getString(1); String id1=rs.getString(2); System.out.println(id+"\t"+id1); } System.out.println(":Records are Successfully Inserted:"); } catch(Exception e) { System.out.println("Error"+e); } }} C:\jdk1.3\bin>javac

C:\jdk1.3\bin>java jdbc number name 1 abhiject 12 dhanaraj 21 krishna 25 nandu :Records are Successfully Inserted:

SQL> select * from demo; NO NAME ---------- ---------1 abhiject 12 dhanaraj 21 krishna 25 nandu

Result: Thus SQL was embedded with a high level language and executed successfully by using statement and prepares statement.


Ex. No: 05 SIMPLE SERVLET APPLICATION AIM To create a simple application in Servlet. PROCEDURE File ->New Project->Web Application1 Right click on WebApplication1 and select New->Servlet Give the name of file as Sample1 Right click on WebApplication1 and select New->html Give the name as Sample import*; import*; import javax.servlet.*; import javax.servlet.http.*; public class Sample1 extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String name=request.getParameter("name"); String email=request.getParameter("email"); try { out.println("<html>"); out.println("<head>"); out.println("<title>Servlet Sample1</title>"); out.println("</head>"); out.println("<body>"); out.println("<p>Name:"+name+"<br>"); out.println("Email:"+email+"<br"); out.println("</body>"); out.println("</html>"); } finally { out.close();



Create a new html file and rename it to sample1.html Sample1.html <html><body><form method=get action=http://localhost:8080/WebApplication1/Sample1> <input type=text name=name size=30> <input type=text name=email size=30> <input type=submit value=submit> <input type=reset value=clear></body></html> OUTPUT:



Thus the simple servlet application to get the user details has been tested and executed successfully.

Ex. No: 06 AIM


To develop a program to illustrate sessions in servlet. PROCEDURE: Choose File ->New Project->Web Application1 from NetBeans IDE. Write click on WebApplication1 project and select New->Servlet and give name as ShowSession. import*; import javax.servlet.*; import javax.servlet.http.*; import*; import java.util.*; public class ShowSession extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); response.setContentType("text/html"); PrintWriter out = response.getWriter(); String title = "Searching the Web"; String heading; Integer accessCount = new Integer(0);; if (session.isNew()) { heading = "Welcome, Newcomer"; } else { heading = "Welcome Back"; Integer oldAccessCount = // Use getAttribute, not getValue, in version // 2.2 of servlet API. (Integer)session.getValue("accessCount"); if (oldAccessCount != null) { accessCount = new Integer(oldAccessCount.intValue() + 1); }


} // Use putAttribute in version 2.2 of servlet API. session.putValue("accessCount", accessCount); out.println(ServletUtilities.headWithTitle(title) + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=\"CENTER\">" + heading + "</H1>\n" + "<H2>Information on Your Session:</H2>\n" + "<TABLE BORDER=1 ALIGN=CENTER>\n" + "<TR BGCOLOR=\"#FFAD00\">\n" + " <TH>Info Type<TH>Value\n" + "<TR>\n" + " <TD>ID\n" + " <TD>" + session.getId() + "\n" + "<TR>\n" + " <TD>Creation Time\n" + " <TD>" + new Date(session.getCreationTime()) + "\n" + "<TR>\n" + " <TD>Time of Last Access\n" + " <TD>" + new Date(session.getLastAccessedTime()) + "\n" + "<TR>\n" + " <TD>Number of Previous Accesses\n" + " <TD>" + accessCount + "\n" + "</TABLE>\n" + "</BODY></HTML>"); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } OUTPUT:


RESULT: Thus the session management program in servlet has been executed successfully.

Ex. No: 07 AIM


To develop a shopping cart package using Servlet. PROGRAM Shopcart.html

<html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body border="1"> <marquee bgcolor="Red" direction="Right"> <h4> Welcome to online shopping cart </h4> </marquee> <br><br> Please check the items and the quantities to purchase the cloth products <form name="form1" method="GET" action="http://localhost:8080/WebApplication12/shop1"> <table border="1" bgcolor="yellow" align="left"> <tr> <th><h3>Items</h3></th> <th><h3>Quantity</h3></th> <th><h3>Price</h3></th> </tr> <tr> <td><h3><input type="checkbox" name="checkitem" value="tshirt">T-t</h3></td> <td align="center"> <select name="Quantitylist"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select></td> <td><h3>Rs:110</h3></td></tr> <tr> <td><h3><input type="checkbox" name="checkitem" value="pant">Pant</h3></td> <td align="center">


<select name="Quantitylist"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select></td> <td><h3>Rs:300</h3></td></tr> <tr> <td><h3><input type="checkbox" name="checkitem" value="shirt">Shirt</h3></td> <td align="center"> <select name="Quantitylist"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select></td> <td><h3>Rs:385</h3></td></tr> </table><br><br> <br><br> <input type="Submit" name="button1" value="Add to cart"> </form></body></html> import*; import javax.servlet.*; import javax.servlet.http.*; public class shop1 extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<body bgcolor=#F5DEB3> <marquee bgcolor=Red direction = Right> Online shopping cart</marquee><br><b>"+ "Please check the items and the quantites to purchase the cloth products</b>"); HttpSession session=request.getSession(); String[] item=request.getParameterValues("checkitem"); String[] qty=request.getParameterValues("Quantitylist"); session.removeValue("tshirt"); session.removeValue("pant"); session.removeValue("shirt"); if(item!=null) { for (int i=0;i<item.length;i++) session.putValue(item[i],qty[i] ); }out.println("<form name=form2 method=GET action=http://localhost:8080/WebApplication12/shop21>"); out.println("<table border=1 align=left>"); out.println("<tr><th>Items</th><th>Quantitylist</th><th>Price</th></tr>); out.println("<tr><td align =left><input type=checkbox name=checkitem value=hd> Headsets</td>"+"<td align=center> <select name=quantitylist><option>1</option><option>2</option><option>3</option><option>4</option><option> 5</option></select></td><td>Rs:120</td></tr><br>"); out.println("<tr><td align =left><input type=checkbox name=checkitem value=hp> Headphones</td>"+"<td align=center> <select name=quantitylist><option>1</option><option>2</option><option>3</option><option>4</option><option> 5</option></select></td><td>Rs:130</td></tr><br>"); out.println("<tr><td align =left><input type=checkbox name=checkitem value=pd> PortableDVD</td>"+"<td align=center> <select


name=quantitylist><option>1</option><option>2</option><option>3</option><option>4</option><option> 5</option></select></td><td>Rs:3850</td></tr><br>"); out.println("<input type=submit vaue=submit>"); out.println("</form></body></html>"); }} import*; import javax.servlet.*; import javax.servlet.http.*; public class shop21 extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int total=0; int total1=0,total2=0,total3=0,total4=0,total5=0,total6=0; response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<body bgcolor=#F5DEB3> <marquee bgcolor=Red direction = Right> Welcome to Online shopping </marquee><br>"); out.println("<table border=1 align=left>"); out.println("<tr><th align=center>Items</th><th>No of Items</th><th>Unit Price</th><th>Total</th></tr>"); HttpSession session=request.getSession(true); if(session.getValue("tshirt")!=null) { out.println("<tr align=center><th>T-shirt</th> <td align=center>"+session.getValue("tshirt")+ "</td>" + "<td align=center> 110 </td>"); out.println("<td align=center>" + Integer.parseInt((String)session.getValue("tshirt"))*110+"</td></tr>"); total1=Integer.parseInt((String)session.getValue("tshirt"))*110; } if(session.getValue("pant")!=null) { out.println("<tr align=center><th>pant</th> <td align=centre>"+session.getValue("pant")+ "</td>" + "<td align=center> 300 </td>"); out.println("<td align=center>" + Integer.parseInt((String)session.getValue("pant"))*300+"</td></tr>"); total2=Integer.parseInt((String)session.getValue("pant"))*300; } if(session.getValue("shirt")!=null) { out.println("<tr align=center><th>shirt</th> <td align=center>"+session.getValue("shirt")+ "</td>" + "<td align=center> 385 </td>"); out.println("<td align=center>" + Integer.parseInt((String)session.getValue("shirt"))*385+"</td></tr>"); total3=Integer.parseInt((String)session.getValue("shirt"))*385; }String[] item=request.getParameterValues("checkitem"); String[] qty=request.getParameterValues("quantitylist"); if(item==null) { return; } for(int i=0;i<item.length;i++) { if(item[i].equals("hd")) { out.println("<tr align=left><th>Headsets</th>"+"<td align=center>"+qty[0]+"</td>"+"<td align=center> 120</td>"+"<td align=center>"+Integer.parseInt(qty[0])*120+"</td></tr>"); total4 =Integer.parseInt(qty[0])*120; } if(item[i].equals("hp")) { out.println("<tr align=left><th>Headphones</th>"); out.println("<td align=center>"+qty[1]+"</td>"); out.println("<td align=center>130 </td>"); out.println("<td align=center>"+Integer.parseInt(qty[0])*130+"</td></tr>"); total5 =Integer.parseInt(qty[1])*130; } if(item[i].equals("pd")) {


out.println("<tr align=left><th>PortableDVD</th>"); out.println("<td align=center>"+qty[2]+"</td>"); out.println("<td align=center>3850 </td>"); out.println("<td align=center>"+Integer.parseInt(qty[2])*3850+"</td></tr>"); total6 =Integer.parseInt(qty[2])*3850; } }total=total1+total2+total3+total4+total5+total6; out.println("<tr><td align=center>Grand Total</td>"); out.println("<td>--------</td><td>-------</td>"); out.println("<td>"+total+"</td></tr></table></body></html>"); }}

OUTPUT: //shop Welcome to Online shopping please check the items and the quantities to purchase the cloth products items quantity price tshirt pant Shirt
add to cart

rs 110 rs 300 rs 385

1 1

//shop1 Welcome to Online shopping please check items and the quantities to purchase the electronics products items quantity rs120 1 submit headsets headphones portable dvd //shop21 Welcome to Online shopping items t-shirts pants HEADSET no of items unit price total 1 1 1 110 300 120 130 ...... 110 300 120 130 660

rs130 rs 385

1 HEADPHONES grandtotal .......


RESULT: Thus the package for shopping cart has been developed and executed successfully.

Ex. No: 08 AIM


To create a JavaBean Component in NetBeans IDE. DESCRIPTION JAVA BEAN A Java Bean is a reusable software component that can be manipulated visually in a builder tool. A Java Bean is a reusable software component that can be manipulated visually in an application builder tool. The idea is that one can start with a collection of such components, and quickly wire them together to form complex programs without actually writing any new code. JavaBeans takes Java's "Write Once, Run Anywhere" capability and extends it to include "reuse everywhere". "JavaBeans is a portable, platform-independent component model, written in Java." With it, you create small, reusable, software components. A visual "builder" program combines components from disparate sources to create applications quickly and easily. Bean: A Bean is a JavaBeans component. Beans are independent, reusable software modules. Beans may be visible objects, like AWT components, or invisible objects, like queues and stacks. A builder/integration tool manipulates Beans to create applets and applications. PROCEDURE Step 1 - Create a library From a fresh opening of NetBeans, do: file->new project for category choose 'java' for project choose 'java class library' Then choose an appropriate location and name for your library. I chose grlib1 for the name. Step 2 - Create an empty class file->new file for category choose 'java'


for file type choose 'Java Class' click 'next' Enter an appropriate class name. I chose 'grbuttonx'. Leave everything else untouched. Step 3 - Make code changes All beans must contain a constructor with no parameters. My constructor initializes my only property/member variable (img). All beans must contain 'implements Serializable'. You don't need to override any of these functions but you have to have that in your class definition. Serializable lets the IDE save your property values during design time.


Beans apparently need to meet security considerations and so probably won't let you do certain things like access local files. I wanted a button with a cool image so I inherited from JButton. This gave me all kinds of properties and it already serializes everything I care about (don't care about the image as this is loaded in runtime). This is very basic implementation - there is no focus image, no down image, no roll over image. Here's my code: import javax.swing.JButton; import java.awt.*; import; public class grbuttonx extends JButton implements Serializable { private Image img; public grbuttonx() { img=null; } public void setImage(Image i) { img=i; } public void paint(Graphics g) { if (img != null) g.drawImage(img, 0, 0,null); else { g.setColor(; Dimension size = getSize(); g.fillOval(0, 0, size.width, size.height); } } } Step 4 - Fix manifest to show this is a bean library First get to the files tab of your project (ctrl/2 should get you there). In the top level of the tree view it shows your projects. The next level down should have a file called build.xml. Click the plus sign next to it. Then double click any element below build.xml. You should be now editing a file called build-impl.xml. Search for "<manifest" (I include the open < to simplify the search). There should only be one such tag in the file and you should be in the jar building section (scroll up to see the next comment block if you want to double check). There should already be 2 attributes in the manifest. Add one called Java-Bean as shown: <manifest> <attribute name="Main-Class" value="${main.class}"/> <attribute name="Class-Path" value="${jar.classpath}"/> <attribute name="Java-Bean" value="true"/> </manifest> Now build your library! Step 5 - test it!


Create a new project or open an existing project. Open a frame or a form or something that allows you to drop buttons onto it. Get into design mode so you can see the palette window. In menu system do: tools -> palette -> Swing/AWT Components there should be 3 buttons. Eventually you might want to choose Add from JAR but we will do: Add From Project... There may be a delay at this point. Navigate if necessary and choose your library project created in step 1. Click next. Your component should show up. Click it and click 'next' again. Select a folder to put your bean into - I always choose "Beans". Click 'finish'. Now you should see your bean in the palette near the bottom in the Beans section. Open up the beans section if it isn't already. Click your bean and then click in your window to place it.


Ex. No: 09


AIM: To develop a simple COM component in VB and to use them in application. DESCRIPTION ActiveX control is control like all visual basic common controls: Command Button, Label, etc. You can make your own ActiveX control, for example hover button control, and use it in every VB program you make without addition of code. Instead of writing the same code every time you want to use the hover button, make once hover button ActiveX control, and drag it to your form every time you want to use it, like it was the usual Command Button. SOFTWARE REQUIREMENTS Visual Basic 6.0 PROCEDURE 1. Choose from the menu (in VB 6.0) File->New Project.

2. Select ActiveX Control and press OK.

A new form without a title bar has been opened.

3. Choose from the menu Project->Project1 Properties.


4. In the 'Project Name' Text Box is written by default 'Project1'

Change the 'Project Name' to myFirstOCX. This is what you will see, after you complete the control, In the Project->Components menu - where the user choose which OCX controls to add to his project

5. Right click on the form, and choose properties from the menu.

The form's name property by default is UserControl1.Change it to MyControl. Starting the Programming Add the necessary controls to create a simple calculator control. Enter the following code to let the user to have a simple calculator control instead of writing code for arithmetic manipulations.
//Component Code Dim sum as Double Dim op as String Dim num as Boolean Private Sub Command1_Click() If num = false then Text1.text = 1 Else Text1.text=Text1.text + 1 End If num = true End Sub Private Sub Command2_Click() If num = false then Text1.text = 2


Else Text1.text=Text1.text + 2 End If num = true End Sub Private Sub Command3_Click() If num = false then Text1.text = 3 Else Text1.text=Text1.text + 3 End If num = true End Sub Private Sub Command4_Click() If num = false then Text1.text = 4 Else Text1.text=Text1.text + 4 End If num = true End Sub Private Sub Command5_Click() If num = false then Text1.text = 5 Else Text1.text=Text1.text + 5 End If num = true End Sub Private Sub Command6_Click() If num = false then Text1.text = 6 Else Text1.text=Text1.text + 6 End If num = true End Sub Private Sub Command7_Click() If num = false then Text1.text = 7 Else Text1.text=Text1.text + 7 End If num = true End Sub Private Sub Command8_Click() If num = false then Text1.text = 8 Else Text1.text=Text1.text + 8 End If num = true End Sub Private Sub Command9_Click() If num = false then Text1.text = 9


Else Text1.text=Text1.text + 9 End If num = true End Sub Private Sub Command10_Click() If num = false then Text1.text = 0 Else Text1.text=Text1.text + 0 End If num = true End Sub Private Sub Command11_Click() If num = false then Text1.text = 0. Else Text1.text=Text1.text + . End If num = true End Sub Private Sub Command12_Click() If op = + then Text1.text = sum + val (Text1.text) Else if op = - then Text1.text = sum - val (Text1.text) Else if op = * then Text1.text = sum * val (Text1.text) Else if op = / then Text1.text = sum / val (Text1.text) End If sum = 0 op = = num = false End Sub Private Sub Command13_Click() Text1.text = num = false End Sub Private Sub Command14_Click() If op = + then sum = sum + val (Text1.text) Else if op = - then sum = sum - val (Text1.text) Else if op = * then sum = sum * val (Text1.text) Else if op = / then sum = sum / val (Text1.text) Else sum = val(Text1.text) End If op = + num = false End Sub Private Sub Command15_Click() If op = + then


sum = sum + val (Text1.text) Else if op = - then sum = sum - val (Text1.text) Else if op = * then sum = sum * val (Text1.text) Else if op = / then sum = sum / val (Text1.text) Else sum = val(Text1.text) End If op = - num = false End Sub Private Sub Command16_Click() If op = + then sum = sum + val (Text1.text) Else if op = - then sum = sum - val (Text1.text) Else if op = * then sum = sum * val (Text1.text) Else if op = / then sum = sum / val (Text1.text) Else sum = val(Text1.text) End If op = * num = false End Sub Private Sub Command17_Click() If op = + then sum = sum + val (Text1.text) Else if op = - then sum = sum - val (Text1.text) Else if op = * then sum = sum * val (Text1.text) Else if op = / then sum = sum / val (Text1.text) Else sum = val(Text1.text) End If op = / num = false End Sub

Compiling and running the control Save the project (File->Save Project).

lets compile the project to OCX Control. From the menu, choose File->Make MyFirstOCX.ocx and press OK.


Now your OCX Control has been created, and registered with your system. Start a new project and enter your control to the project (From the menu choose Project>Components , mark the MyFirstOCX checkBox and press OK.

Now you see the new control at the ToolBox.

Insert it to your form, resize it to your preferred size, press the buttons to select the numbers and perform manipulations on those numbers.

RESULT Thus the program for developing a COM component for a simple calculator using ActiveX control has been executed successfully.


Ex. No:11 AIM


To develop a simple package using JSP. PROGRAM: package foo; public class usebeanexample { private String message = "No message specified"; public String getMessage() { return(message);} public void setMessage(String message) { this.message = message;} } Usebean.jsp <HTML> <head> <TITLE>JavaBeans in JSP</TITLE> <meta http-equiv="Content-Language" content="en-us"> <style type="text/css"> .style1 { border: 2px solid #0000FF; background-color: #CCFFFF; } </style> </head> <BODY> <table class="style1" style="float: CENTER" align="center"> <tr> <td style="width: 430px; height: 38px"> <h3><strong>EXAMPLE OF JSP:USEBEAN STANDARD ACTION</strong></h3> </td> </tr> </table> <P> <jsp:useBean id="test" class="foo.usebeanexample" /> <jsp:setProperty name="test" property="message" value="Hello User" /> <center><H1>Message: <jsp:getProperty name="test" property="message" /> </H1></center> </BODY> </HTML>


Ex. No:12 AIM


To deploy an EJB for converting Fahrenheit to Celsius by simple arithmetic operator. DESCRIPTION Enterprise JavaBeans (EJB) technology is the server-side component architecture for Java Platform, Enterprise Edition (Java EE). EJB technology enables rapid and simplified development of distributed, transactional, secure and portable applications based on Java technology. EJB architecture provides a framework for creation of distributed ntier middleware applications. It enables the development and deployment of robust, transactional and scalable component-based business applications. A bean is a server side component that executes specific business logic. It is deployed on an application server and provides services to local and remote clients. It gets the services of the application server by establishing a standardized contract between the application server and the component. A typical EJB framework consists of the following components. 1. 2. 3. 4. EJB Server. EJB Container. Enterprise Beans. EJB Client.

SOFTWARE REQUIREMENTS 1. JDK1.5 2. Sun Microsoft J2EE Application Server PROCEDURE STEP1: Write the source code for the remote interface for EJB and save it as // import javax.ejb.EJBObject; import java.rmi.RemoteException; public interface Temperature extends EJBObject {public double FahrenheitToCelsius(double degree)throws RemoteException; } STEP2: Write the source code for Stateless Session Bean class and save it as // import java.rmi.RemoteException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; public class TemperatureEJB implements SessionBean {public double FahrenheitToCelsius(double f)


{double c;c=((f-32)*5)/9; return c;} public TemperatureEJB() {} public void ejbCreate() {} public void ejbRemove() {} public void ejbActivate() {} public void ejbPassivate() {} public void setSessionContext(SessionContext sc) {} } STEP 3: Write the source code for home interface called // import; import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.EJBHome; public interface TemperatureHome extends EJBHome {Temperature create() throws RemoteException ,CreateException; } STEP 4: Deploy the EJB created by the j2ee deployment tool. DEPLOYMENT C:\> j2ee verbose C:\> deploytool Deployment tool version 1.2.1 Type deploytool help for command line options. Starting Choose File New Application. The new application window will be appeared as shown below

Locate the folder C:\temperature using Browse button. Type TemperatureApp in Application Display Name text field and click OK. Choose File New Enterprise Bean. The New Enterprise Bean wizard will be opened. Read the instruction and click Next button in the first page of the wizard. Type the JAR Display name as TemperatureAppClient in the next page that is shown.


Click Add button that appear under the Contents area. Addfiles to .JAR dialog box will be displayed. Click Browse button and choose Temperature.class, TemperatureHome.class and TemperatureEJB.class. Click Add button. Click Next button. The next page will be displayed as shown. Choose TemperatureEJB in Enterprise Bean Class combo box. Choose TemperatureHome in Home Interface combo box. Type TemperatureBean in Enterprise Bean Display Name text field. Choose session radio button in Bean type and select stateless. Click Finish button. Choose Tools Deploy Application.The Deploy wizard will be opened as shown. Choose localhost in the TargetServer combo box. Tick the Return Client Jar check box. Type C:|\Temperature\TemperatureAppClient.jar in the text field. Click Next button.


STEP 5: Write the source code for the client for the EJB deployed. // import javax.naming.Context; import*; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; import Temperature; import TemperatureHome; public class TemperatureClient {public static void main(String[] args) {TemperatureHome home; BufferedReader stdin; try{Context initial=new InitialContext(); Object objref=initial.lookup("MyTemperature"); home=(TemperatureHome)PortableRemoteObject.narrow(objref,TemperatureHome.class); Temperature degreeConverter=home.create(); try{double f=0; while(f!='q') {stdin=new BufferedReader(new InputStreamReader(; System.out.println("\n\nEnter the temperature in Fahrenheit(Type 'q' to Quit):"); f=Double.parseDouble(stdin.readLine()); double cel=degreeConverter.FahrenheitToCelsius(f); System.out.println("The temperature in celsius:"+String.valueOf(cel)); }}catch(Exception e) {System.out.println("Thank you"); degreeConverter. remove(); }}catch(Exception ex) {System.out.println("Caught on unexpected exception!"); ex.printStackTrace(); }}}


COMPILATION Compile.bat Set CPATH=;c:\j2sdkee1.2.1\lib\j2ee.jar Javac classpath %CPATH% Compile1.bat Set CPATH=.;c:\j2sdkee1.2.1\lib\j2ee.jar;c:\j2sdkee1.2.1\Temperature Javac classpath %CPATH% EXECTION Run.bat Set CPATH=.;c:\j2sdkee1.2.1\lib\j2ee.jar; TemperatureAppClient.jar Java D0rg.omg.CORBA.ORBInitialHost=localhost classpath %CPATH% TemperatureClient. OUTPUT:

RESULT: Thus the program for deployment of EJB for temperature conversion has been executed.