You are on page 1of 73

Ex No: 1 Date: 01/07/11 AIM: To develop an RMI application that allows a client to transfer or download any types of files

from a remote machine. ALGORITHM: Step 1: Start the program. Step 2: In the Client, x get the user input for directory, file name. Step 3: Create a new file in the directory with the specified file name. Step 4: Create an object for the remote interface downserver. Step 5: Use lookup() to search for JNDI name and download the file contents. Step 6: The client invokes methods in Remote interface to download the file. Step 7: Compile all the files by using set path= C:\Program Files\Java\jdk1.6.0_02\bin Step 8: Start RMI registry and compile the downimpl program. Step 9: Run the client and display the result. Step 10: Stop the program. SOURCE CODE /* downserver.java */ import java.rmi.*; import java.io.*; public interface downserver extends Remote { String download(File f) throws RemoteException; } /* dclient.java */ import java.rmi.*; import java.io.*; public class dclient { public static void main(String args[])

REMOTE METHOD INVOCATION

-1-

{ try { String file,dir; BufferedReader din=new BufferedReader(new InputStreamReader (System.in)); System.out.println("Enter directory name:"); dir=din.readLine(); System.out.println("Enter the file name:"); file=din.readLine(); File ff=new File(dir,file); downserver dr=(downserver)Naming.lookup("rmi://localhost/downimpl"); String s=dr.download(ff); System.out.println(s); } catch(Exception e) {} }} /* downimpl.java */ import java.rmi.*; import java.io.*; import java.rmi.server.*; public class downimpl extends UnicastRemoteObject implements downserver { public downimpl() throws RemoteException { } public String download(File f) { String str=" "; try { FileInputStream in=new FileInputStream(f); int l=in.available(); -2-

for(int i=1;i<=l;i++) { str+=(char)in.read(); } } catch(Exception e) {} return str; } public static void main(String args[]) { try { downimpl d=new downimpl(); Naming.rebind("rmi://localhost/downimpl",d); } catch(Exception e) {}} PROCEDURE TO EXECUTE 1. Compile the java files by using set path= C:\Program Files\Java\jdk1.6.0_02\bin 2. Start rmiregistry. 3. Start java downimpl. 4. Run the client using java dclient. SCREEN OUTPUT:

The above snapshot describes the compilation of all java files Next we will start the rmiregistry using the following command.

Now we will get the rmiregistry window dialog box

-3-

Next we will run the server program (downimpl.java) in following manner

Now we will open another command prompt and run the client program (dclient.java) in following manner. We will get the output.

RESULT Thus the above application Remote Method Invocation has been executed successfully. -4-

Ex No:2 Date: 08/07/11 AIM: To implement the Java Bean to draw graphical objects and to display it in Frame. ALGORITHM Step 1: Start->All Programs->Net BeansIDE Choose File->New Project in dialog Box. Choose category as General and select Project as Java Application.

CREATING JAVA BEAN

Step2 : Give Project name: JavaBean & deselect Create Main class and set as Main project. Click finish to create the class.

-5-

Now we will get the following window.

Right Click Java Bean->New->Java Class and give class name as JavaBean

Step 3: In left pane Double click on JavaBean.java. Now in right side pane type the corresponding code. Step 4: Now we compile the JavaBean.java code in following manner. In left side panner Right click the JavaBean.java -> Compile File

-6-

Step 5: Next we will select Files Tab in Left Side Pane and double click the build.xml file from JavaBean Folder. Now we add our own xml - code after the comment with in the <project></project> tag. Step 6: Now we compile the above build.xml code in the following manner. Right Click build.xml -> Run Target -> Other Targets -> build Please following the below screen.

Step 7: Next we double click the JavaBean.jar file from left pane in Files Tab, we got MANIFEST.MF file.

Now we will open the MANIFEST.MF (Double click) file and check the following information is correct or not. Name: JavaBean.class Java-Bean: true Step 8: Next we will create one Java Frame class in the following manner Select Projects Tab ->JavaBean Right Click -> New JFrame Form. Now we give the class name as BeanLoader and click finish.

-7-

Step 9: In palette Explorer (it available from Right side) Right click the Palette Explorer - >Choose Palette Manager. Now we will get the following Dialog box.

Step 10: In palette Manager Dialog box Please click the Add from JAR Button Now we will get the following Dialog box

Please select the appropriate JavaBean.jar file from your corresponding Project Folder then click -> next Now choose the available components to add to the palette then click->next Now choose the palette category where to add the components. Here Beans has been selected. Then click finish.

-8-

Now the Palette Manager Dialog box will appear with selection of Beans Component then ->close. Now go to Palette Explorer and Click the Beans Division check whether the corresponding JavaBean has been added or not. Now Drop the JavaBean Component from Beans Division and drag into the BeanLoader.java Frame window. Next we will run the BeanLoader.java. Right click BeanLoader.java -> click Run File. Now we got the following output SOURCE CODE File Name: JavaBean.java import java.awt.Color; import java.beans.XMLDecoder; import javax.swing.JLabel; import java.io.Serializable; public class JavaBean extends JLabel implements Serializable { public JavaBean() { setText( "MiddleWare" ); setOpaque( true ); setBackground( Color.RED ); setForeground( Color.YELLOW ); setVerticalAlignment( CENTER );

-9-

setHorizontalAlignment( CENTER ); } } XML coding: <dirname property="basedir" file="${ant.file}"/> <property name="beanname" value="JavaBean"/> <property name="jarfile" value="${basedir}/${beanname}.jar"/> <target name="build" depends="compile"> <jar destfile="${jarfile}" basedir="${basedir}" includes="*.class"> <manifest> <section name="${beanname}.class"> <attribute name="Java-Bean" value="true"/> </section> </manifest> </jar> </target> <target name="compile"> <javac destdir="${basedir}"> <src location="${basedir}"/> </javac> </target> <target name="clean"> <delete file="${jarfile}"> <fileset dir="${basedir}" includes="*.class"/> </delete> </target> SCREEN OUTPUT

RESULT: Thus the above application Java Beans has been executed successfully.

- 10 -

Ex No: 3 Date: 15/07/11 AIM: To develop a simple calculator in EJB Application to perform a basic mathematical operations. PROCEDURE / ALGORITHM Step1: Start All ProgramsNetBeansFile Menu Select New Project Choose Java (Categories) and Enterprise Application (Projects)and click next.

CREATING A SIMPLE CALCULATOR USING EJB

Step : 2 In Name and Location Menu give the Project name and Click Next. Set the Server as Glass Fish, Select the Java Version, Check the Selection of EJB Module and Web Application Module and click finish.

- 11 -

Step 3: Ensure the name of the Project (Calculator), EJB Module(Calculator-ejb) and Web Application module (Calculator-war) was created. Right Click EJB Module Select Session Bean Give EJB Name Give Package Name Select the Session type as Stateless Check the interface as Remote click Finish.

- 12 -

Step 4: Ensure the Creation of a Bean (CalculatorBean) and Remote interface (CalculatorBeanRemote) file Type the coding for the Remote interface java file Type the coding in the Java Bean file Step 5: Select The Web Application module (War File), Right click on WebPages Select jsp/ html Create the Client form (form.jsp) type the following code in form.jsp

Type the Coding for form.jsp Step 6: Now Create a Servlet file to handle the client request. The Request method was either GET/POST. Right click on the source package of Calculator-war and select Servlet and name it as WebServlet and click finish

- 13 -

Step7:. Inserting the Enterprise Bean in the Servlet File. Right Click inside the Servlet file (WebServlet.java) Select Insert code Select Call Enterprise Bean Select the Enterprise Bean (CalculatorBean) click Ok. Ensure the import statement coding has the import calculator.CalculatorRemote; and in the Coding line @EJB private CalculatorRemote calculatorBean; Type the coding for WebServlet.java

- 14 -

Step 8: Build, Deploy and Run the Project Right click the Project Select Clean & Build Right Click the Project Select Deploy Right Click the Project Run Clean & Build

Deploy & Run

Step 9: Observe the output in Web Browser

- 15 -

SOURCE CODE CalculatorBeanRemote.java package calculator; import javax.ejb.Remote; import java.math.*; import java.lang.annotation.*; @Remote public interface CalculatorRemote { public float add(float x,float y); public float subtract(float x,float y); public float multiply(float x,float y); public float division(float x,float y); } CalculatorBean.java package calculator; import javax.ejb.Stateless; import java.math.*; import javax.ejb.Remote; @Stateless(name="CalculatorBean") @Remote(CalculatorRemote.class) public class CalculatorBean implements CalculatorRemote { public float add(float x,float y) { return x+y; { return x-y; { return x*y; } } } public float subtract(float x,float y) public float multiply(float x,float y) public float division(float x,float y) { return x/y; } }

- 16 -

form.jsp <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Calculator</title></head> <body bgcolor="gray"> <center><h1>Calculator</h1></center> <form action="Webservlet" method="get"> <table align="center" bgcolor="white" width="350" height="450" > <tr><td>Enter <tr><td> Enter first second value:</td><td><input value:</td><td><input type="text" type="text" name="num1" name="num2" size="25"></td></tr> size="25"></td></tr> <tr><td>Select your choice</td></tr> <tr><td align="right"><input type="radio" name="group1" value="add"></td><td>Addition</td></tr><tr><td align="right"><input type="radio" name="group1" value="subtract"></td><td>Subtraction</td></tr> <tr><td align="right"><input type="radio" name="group1" value="multiply"></td><td>Multiplication</td></tr><tr><td <tr><td><input type="submit" align="right"><input type="reset" type="radio" name="group1" value="division"></td><td>Division</td></tr> value="submit"></td><td><input value="reset"></td></tr></table></form></body></html> index.jsp <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF8"><title>JSP Page</title></head> <body><center><h2>Welcome </h2></center><center><a Bean</a></center></body></html> WebServlet.java import java.io.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; import javax.ejb.*; import calculator.CalculatorRemote; - 17 to EJB Stateless to Session call Bean the href="form.jsp">Click

public class Webservlet extends HttpServlet { @EJB private CalculatorRemote calculatorBean; protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out=response.getWriter(); float result=0; System.out.println(result); try { String s1=request.getParameter("num1"); String s2=request.getParameter("num2"); String s3=request.getParameter("group1"); if(s1!=null && s2!=null) { System.out.println(s3); Float num1=new Float(s1); Float num2=new Float(s2); if(s3.equals("add")) { result=calculatorBean.add(num1.floatValue(),num2.floatValue()); out.println(<html><body>); out.println("<center><h1>The Result For The Choice ADDITION</h1></center><br>"); out.println("<table border=10 bgcolor=gray align=center>"); out.println("<tr><td><center><h2>The Number1 is: "+num1+"</h2></center></td></tr>"); out.println("<tr><td><center><h2>The Number2 is: "+num2+"</h2></center></td></tr>"); out.println("<tr><td><center><h2>The Result is: "+result+"</h2></center></td></tr>"); out.println("</table></body></html>""); } else if(s3.equals("subtract")) { result=calculatorBean.subtract(num1.floatValue(),num2.floatValue()); out.println("<html><body>"); - 18 -

out.println("<center><h1>The Result For The Choice SUBTRACT</h1></center><br>"); out.println("<table border=10 bgcolor=gray align=center>"); out.println("<tr><td><center><h2>The Number1 is: "+num1+"</h2></center></td></tr>"); out.println("<tr><td><center><h2>The Number2 is: "+num2+"</h2></center></td></tr>"); out.println("<tr><td><center><h2>The Result is: "+result+"</h2></center></td></tr>"); out.println("</table></body></html>"); } else if(s3.equals("multiply")) { result=calculatorBean.multiply(num1.floatValue(), num2.floatValue()); out.println("<html><body>"); out.println("<center><h1>The Result For The Choice MULTIPLICATION </h1></center><br>"); out.println("<table border=10 bgcolor=gray align=center>"); out.println("<tr><td><center><h2>The Number1 is: "+num1+"</h2></center></td></tr>"); out.println("<tr><td><center><h2>The Number2 is: "+num2+"</h2></center></td></tr>"); out.println("<tr><td><center><h2>The Result is: "+result+"</h2></center></td></tr>"); out.println("</table></body></html>"); } else { result=calculatorBean.division(num1.floatValue(),num2.floatValue()); out.println("<html><body>"); out.println("<center><h1>The Result For The Choice DIVISION</h1></center><br>"); out.println("<table border=10 bgcolor=gray align=center>"); out.println("<tr><td><center><h2>The Number1 is: "+num1+"</h2></center></td></tr>"); out.println("<tr><td><center><h2>The Number2 is: "+num2+"</h2></center></td></tr>"); out.println("<tr><td><center><h2>The Result is: - 19 -

"+result+"</h2></center></td></tr>"); out.println("</table></body></html>"); } } } catch(Exception e) { e.printStackTrace(); } } SCREEN OUTPUT Screen shot 1:

Screen shot 2:

- 20 -

Screen Shot 3:

RESULT Thus the above application Simple Calculator using EJB has been executed successfully.

- 21 -

Ex No: 4 Date: 22/07/11 AIM: To develop a simple EJB Application to perform a Bank Transaction operations. PROCEDURE / ALGORITHM Step1: Start All ProgramsNetBeansFile Menu Select New Project Choose Java (Categories) and Enterprise Application (Projects) and click next.

CREATING A SIMPLE BANK TRANSACTION USING EJB

Step: 2 In Name and Location Menu give the Project name and Click Next. Set the Server as Glass Fish, Select the Java Version, Check the Selection of EJB Module and Web Application Module and click finish.

- 22 -

Step 3: Ensure created. Right Click EJB Module Select Session Bean Give EJB Name Give Package Name Select the Session type as Stateful Check the interface as Remote click Finish. the name of the Project (BankApplication), EJB Module (BankApplication-ejb) and Web Application module (BankApplication-war) was

- 23 -

Step4: Ensure the Creation of a Bean (BankApplication.java) and Remote interface (BankApplicationRemote.java) file Type the coding for the Remote interface java file Type the coding in the Java Bean file Step5: Select The Web Application module (War File), Right click on WebPages Select jsp/ html Create the Client form (BankForm.jsp) type the following code in BankForm.jsp

- 24 -

Type the Coding for BankForm.jsp Step 6 Now Create a Servlet file to handle the client request. The Request method was either GET/POST. Right click on the source package of BankApplication-war and select Servlet and name it as BankServlet and click finish

- 25 -

Step7:. Inserting the Enterprise Bean in the Servlet File. Right Click inside the Servlet file (BankServlet.java) Select Insert code Select Call Enterprise Bean Select the Enterprise Bean (BankApplication) click Ok. Ensure the import statement coding has the import BankApplication.BankApplicationRemote; and in the Coding line BankApplicationRemote bankApplication = lookupBankApplicationRemote(); Type the coding for BankServlet.java

Step 8:

- 26 -

Build, Deploy and Run the Project Right click the Project Select Clean & Build Right Click the Project Select Deploy Right Click the Project Run Clean & Build

Deploy & Run

Step 9: Observe the output in Web Browser

- 27 -

SOURCE CODE BankApplicationRemote.java package BankApplication; import javax.ejb.Remote; import javax.ejb.Remove; @Remote public interface BankApplicationRemote { public float deposit(float amount); public float withdraw(float amount); public void remove(); } BankApplication.java package BankApplication; import javax.ejb.Stateful; import javax.ejb.Remote; import javax.ejb.Remove; @Stateful public class BankApplication implements BankApplicationRemote { float balance = 0; public float deposit(float amount) { balance += amount; return balance; } public float withdraw(float amount) { balance -= amount; return balance; } public void remove() { balance = 0; } } BankForm.jsp <html> <head> <title>Bank Account</title> </head><body> <p align="center"><font size="6" color="#800000"/>Bank Transaction Request Form </p> <form action="BankServlet" method=get> <table bgcolor="#FFFFCC" align="center">

- 28 -

<tr>

<td>Enter

the

amount your

in

rupees:

<input

type="text"

name="amt" type="radio"

size="10"></td></tr> <tr><td><b>Select choice:</b></td></tr><tr><td><input name="group1" value ="dep">Deposit</td></tr> <tr><td><input type="radio" name="group1" value ="with">Withdraw<br></td></tr> <tr><td><input type="submit" value="Transmit"><input type="reset" value="Reset"></td></tr> </table> </form></body></html> index.jsp <html> <head> <title>JSP Page</title></head> <body> <center><h2>Welcome to EJB Stateful Session Bean </h2></center> <center><a href="BankForm.jsp">Click to call the Bean</a></center> </body></html> BankServlet.java import BankApplication.BankApplicationRemote; import java.io.IOException; import java.io.PrintWriter; import java.util.logging.Level; import java.util.logging.Logger; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class BankServlet extends HttpServlet { BankApplicationRemote bankApplication = lookupBankApplicationRemote(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // processRequest(request, response); - 29 -

response.setContentType("text/html;charset=UTF-8"); PrintWriter out=response.getWriter(); float result=0; try { String s1=request.getParameter("amt"); String s2=request.getParameter("group1"); if(s1!=null && s2!=null) Float amt=new Float(s1); if(s2.equals("dep")) out.println("<html><body>"); out.println("<p align='center'><font size='6' color='#800000'/>Bank Transaction Form </p>"); out.println("<table bgcolor='#FFFFCC' align='center'>"); out.println("<tr><td><center> <h1>Rs."+amt+"</h1> <h2>/-was Deposited in your Account</h2></center></td></tr>"); out.println("<tr><td><center> </h1></center></td></tr>"); out.println("<tr><td><center><h3><a Form</a></h3></center></td></tr>"); out.println("</table></body></html>"); else if(s2.equals("with")) out.println("<html><body>"); out.println("<p align='center'><font size='6' color='#800000'/>Bank Transaction Form </p>"); out.println("<table bgcolor='#FFFFCC' align='center'>"); out.println("<tr><td><center> <h1>Rs."+amt+"</h1> <h2>/-was With Drawn From your Account</h2></center></td></tr>"); out.println("<tr><td><center> </h1></center></td></tr>"); out.println("<tr><td><center><h3><a Form</a></h3></center></td></tr>"); out.println("</table></body></html>"); } } } - 30 href='BankForm.jsp'>Back To Transaction <h2>current balance is</h2><h1>Rs."+result+"/{ } href='BankForm.jsp'>Back To Transaction <h2>current balance is</h2><h1>Rs."+result+"/{ result=bankApplication.deposit(amt.floatValue()); {

result=bankApplication.withdraw(amt.floatValue());

catch(Exception e) { e.printStackTrace(); } } SCREEN OUTPUT Screen shot 1:

Screen shot 2:

- 31 -

Screen Shot 3:

Screen Shot 4:

RESULT The above application Simple Bank Transaction using EJB has been executed successfully.

- 32 -

Ex No: 5 Date: 29/07/11

CREATING A SIMPLE LIBRARY MANAGEMENT USING EJB

AIM: To develop a simple EJB Application to perform Library Management operations. PROCEDURE / ALGORITHM Step1: Start All ProgramsNetBeansFile Menu Select New Project Choose Java (Categories) and Enterprise Application (Projects) and click next.

Step 2 In Name and Location Menu give the Project name and Click Next. Set the Server as Glass Fish, Select the Java Version, Check the Selection of EJB Module and Web Application Module and click finish.

- 33 -

Step 3: Ensure the name of the Project (LIB), EJB Module (LIB-ejb) and Web Application module (LIB-war) was created. Right Click EJB Module Select Session Bean Give EJB Name Give Package Name Select the Session type as Stateful Check the interface as Remote click Finish.

- 34 -

Step4: Ensure the Creation of a Bean (LIBBean.java) and Remote interface (LIBBeanRemote.java) file Type the coding for the Remote interface java file Type the coding in the Java Bean file Step5: Select The Web Application module (War File), Right click on WebPages Select jsp/ html Create the Client form (LIBForm.jsp) type the following code in LIBForm.jsp

Type the Coding for LIBForm.jsp Step6: Now Create a Servlet file to handle the client request. The Request method was either GET/POST. Right click on the source package of LIB-war and select Servlet and name it as LIBServ.java and click finish

- 35 -

Step7: Inserting the Enterprise Bean in the Servlet File. Right Click inside the Servlet file (LIBServ.java) Select Insert code Select Call Enterprise Bean Select the Enterprise Bean (LIBBean) click Ok. Ensure the import statement coding has the import LIB.LIBBeanRemote; and in the Coding line LIBBeanRemote lIBBean = lookupLIBBeanRemote(); Type the coding for LIBServ.java

- 36 -

Step 8: Build, Deploy and Run the Project Right click the Project Select Clean & Build Right Click the Project Select Deploy Right Click the Project Run Clean & Build

Deploy

- 37 -

Step 9: Observe the output in Web Browser SOURCE CODE LIBBeanRemote.java package LIB; import javax.ejb.Remote; import java.rmi.RemoteException; @Remote public interface LIBBeanRemote { public String Issue(String acno,String bname)throws RemoteException; public String Return(String acno)throws RemoteException; } LIBBean.java package LIB; import javax.ejb.Stateful; @Stateful public class LIBBean implements LIBBeanRemote { private static int count=0; private String c_no[]=new String[100]; - 38 -

private String ac_no[]=new String[100]; @Override public String Issue(String acno,String bname) ac_no[count]=acno; c_no[count]=bname; count++; return "Successfully Issued"; @Override public String Return(String acno) for(int i=0;i<count;i++) if(ac_no[i].equals(acno)) { ac_no[i]=""; c_no[i]=""; return "Successfully Returned"; } return "Not Available"; LIBForm.jsp <html> <head> <title>Library Request Form</title></head><body> <h1 align="center">Library the Book Request Account Form</h1><form action="LIBServ" type="text" method="get"><table cellspcaing="5" cellpadding="5" border="1"> <tr><td>Enter Number</td><td><input name="acno"></td></tr> <tr><td>Enter the Book Title</td><td><input type="text" name="bname"></td> </tr><tr><td>Select Ur Choice</td> </tr> <tr> <td align="center"><input type="radio" name="group1" value="iss">Issue</td> </tr><tr><td align="center"><input type="radio" name="group1" value="with">Return</td></tr> <tr><td><input type="submit" value="Transmit"></td><td><input type="reset" value="Reset"></td> </tr></table></form></body></html> index.jsp <html> <head> <title>JSP Page</title></head> <body><center><h2>Welcome to EJB Stateful Session Bean </h2></center> <center><a href="LIBForm.jsp">Click to call the Bean</a></center> </body></html> } } { } {

- 39 -

LIBServ.java import LIB.LIBBeanRemote; import java.io.IOException; import java.io.PrintWriter; import java.util.logging.Level; import java.util.logging.Logger; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class LIBServ extends HttpServlet { LIBBeanRemote lIBBean = lookupLIBBeanRemote(); @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // processRequest(request, response); response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String result=""; try { String s1=request.getParameter("acno"); String s2=request.getParameter("bname"); String s3=request.getParameter("group1"); if(s1!=null && s2!=null) if(s3.equals("iss")) { {

result=lIBBean.Issue(s1,s2); out.println("<h1>Welcome</h1>");

- 40 -

out.println("<h1>The Book Bearing Account No" + s1 + "and title" + s2 + "was" + result + "</h1>"); { result=lIBBean.Return(s1); out.println("<h1>The Book Bearing Account No" + s1 + "was" + result + "</h1>"); } } out.println("<a href=form1.jsp>Go Home Page</a>"); catch(Exception e){} } } } else if(s3.equals("with"))

- 41 -

SCREEN OUTPUT Screen shot 1:

Screen shot 2:

Screen Shot 3

RESULT Thus the above application Library Management System using EJB has been executed successfully.

- 42 -

Ex No: 6 Date: 05/08/11 AIM: To write a program to create an Active-X control in C#.NET ALGORITHM: Step 1: Start the process Step 2: Click start->All programs->Microsoft Visual Studio 2005-> Microsoft Visual Studio 2005->File->New Project->Project Types as Visual C# and Templates as Windows Application Step 3: Design the form with the following controls in the form RichTextBox Save Command Button Open Command Button Color Command Button SaveFileDialog Control OpenFileDialog control ColorDialog Control Step 4: Write event handling procedures for Save, Open and Color commands Step5: Execute the program Step 6: Stop the program FORM DESIGN

ACTIVEX CONTROL

- 43 -

SOURCE CODE using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace ActControl { public partial class Form1 : Form public Form1() { { richTextBox1.Enabled = true; richTextBox1.Text = ""; richTextBox1.Focus(); } private void button2_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() != DialogResult.Cancel) { - 44 InitializeComponent(); } private void button1_Click(object sender, EventArgs e) {

richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText); { if (saveFileDialog1.ShowDialog() != DialogResult.Cancel) { richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText); { if (colorDialog1.ShowDialog() != DialogResult.Cancel) { richTextBox1.SelectionColor = colorDialog1.Color; } } private void button5_Click(object sender, EventArgs e) { if (fontDialog1.ShowDialog() != DialogResult.Cancel) { richTextBox1.SelectionFont = fontDialog1.Font; } } private void Form1_Load(object sender, EventArgs e) { richTextBox1.Enabled = false; } private void button6_Click(object sender, EventArgs e) { this.Close(); } } } SCREEN OUTPUT: Screen shot of SaveFileDialog control to save the Content of Rich text Box to a file } } private void button4_Click(object sender, EventArgs e) } } private void button3_Click(object sender, EventArgs e)

- 45 -

Screen shot of OpenFileDialog control to open the file

- 46 -

Screen shot of FontDialogBox to apply the font settings

RESULT Thus the above application Active-x control has been executed successfully.

- 47 -

Ex No: 7 Date: 12/08/11 AIM To Develop a Component for Currency Conversion using .NET ALGORITHM Step 1: Start the program. Step 2: Goto Start -> All Programs -> MicrosoftVisualStudio 2005. Step 3: In the start page select File -> NewProject. Step 4: Select the desired language and Select the template as WindowsApplication. Give the FileName and Location. Step 5: In the Design view create the Form with the fileds for Entering the amount, Displaying the rupees equivalent, Three Buttons: Calculate, Clear, Exit, Four RadioButtons: US Doller, Pound, Euro, Dinar. Step 6: Run the program using F5. Step 7: Stop the Program. FORM DESIGN

CURRENCY CONVERSION

- 48 -

SOURCE CODE using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace CurrencyConversion { { { public partial class Form1 : Form public Form1() InitializeComponent(); }

// CODE CORRESPONDING TO CALCULATE BUTTON private void button1_Click(object sender, EventArgs e) { Double tot = 0; Double a = Double.Parse(textBox1.Text); if (radioButton1.Checked == true) tot = a * 45.05; else if (radioButton2.Checked == true) tot = a * 71.31; else if (radioButton3.Checked == true) tot = a * 60.66; else tot = a * 119.47; textBox2.Text = tot.ToString("0.000"); } // CODE CORRESPONDING TO CLEAR BUTTON private void button2_Click(object sender, EventArgs e) { textBox1.Text = " "; textBox2.Text = " "; radioButton1.Checked = true; textBox1.Focus(); } - 49 -

// CODE CORRESPONDING TO EXIT BUTTON private void button3_Click(object sender, EventArgs e) { Application.Exit(); } SCREEN OUTPUT }}

RESULT

- 50 -

Thus the above application Currency Conversion using .NET was executed successfully.

- 51 -

Ex No: 8 Date: 27/08/11 AIM: To develop a component for encryption and Decryption using COM / .NET ALGORITHM: Step 1: Goto Start->All Programs->Microsoft Visual Studio. Step 2: In the start page File->New Project select the desired language and select the template as Windows Application by selecting Visual C#, Give the filename and location. Step 3: In design Place the label, textbox, buttons for appropriate operations. Step 4: In Button click event, For Encrypt convert the given string to integer(ASCII values),add 100 with each character and then add the specified length as first letter. Step 5: For Decrypt get the string, take first char as splitting length, using this find the no of character and then subtract with 100 for find the original string. FORM DESIGN:

ENCRYPTION AND DECRYPTION

- 52 -

SOURCE CODE: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace encryption { public partial class Form1 : Form //Define the class which inherits the Form class { string res,receiver; string a; int[] t = new int[100]; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //Code for Encrypting if (button1.Text == "Encrypt") { label1.Text = "Encrypted Text"; //change the label text and button text button1.Text = "Decrpt"; a = textBox1.Text; for (int j = 0; j < 100; j++) t[j] = 0; res = ""; for (int i = 0; i < a.Length; i++) { t[i] = Convert.ToInt32(a[i]); t[i] = t[i] + 100; //add 100 with separated Integer - 53 //Convert to ASCII value and add 100 //separate the letters to int //Initialize all the components //Constructor for the class Form1 //Name space encryption provides working environment //Import the necessary library files

res = res + Convert.ToString(t[i]); } textBox1.Text = "3"+res; receiver = "3"+res; } else { label1.Text = "The Result is"; button1.Text = "Encrypt"; textBox1.Text = ""; char size = receiver[0],solution; string x = Convert.ToString(size); int orgsize = Convert.ToInt32(x); int num = 0, org, l = 1; int size1 = receiver.Length, length = size1 / orgsize, o = orgsize + 1; //To convert the original string for (int i = 0; i < length; i++) { string textt = ""; for (int j =l; j < o ; j++) { textt = textt + Convert.ToChar(receiver[j]); //separate the text and convert to original letter } num = Convert.ToInt32(textt); org = num - 100; solution = Convert.ToChar(org); o += orgsize; l += orgsize; } } } } } //concatenate the string textBox1.Text = textBox1.Text + Convert.ToString(solution); //Read the numbers //Find the legth and size //Specify the spliting length

- 54 -

SCREEN OUTPUT Screen Shot1

Screen Shot 2

- 55 -

Screen Shot 3

RESULT Thus the above application Encryption and Decryption using COM/.NET has been executed successfully.

- 56 -

Ex No:9 Date: 15/09/11 AIM: To develop a component to retrieving the information from Message Box using COM / .NET ALGORITHM Step 1: Start the process. Step 2: Place the controls in form look like given below.

RETERVING INFORMATION FROM MESSAGE BOX

Step 3: Double click on the command button Information and enter the following codes. private void button1_Click(object sender, EventArgs e) { MessageBox.Show("Hi! friends", } "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

Step 5: Double click on the command button Question and enter the following codes. private void button4_Click(object sender, EventArgs e) { dr = MessageBox.Show("Do you wanna continue?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) MessageBox.Show("Yes! else MessageBox.Show("Thanks for being with us", "No", MessageBoxButtons.OK, MessageBoxIcon.Information); } Step 6: Double click on the command button Exclamination and enter the following - 57 you can continue your work", "Yes", MessageBoxButtons.OK, MessageBoxIcon.Information);

Codes. private void button2_Click(object sender, EventArgs e) { MessageBox.Show("Wow! wat a nice picture", "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } Step 7: Double click on the command button Warning and enter the following codes. private void button5_Click(object sender, EventArgs e) { dr = MessageBox.Show("Your system is infected by Virus!", "Warning", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning); if (dr == DialogResult.Retry) MessageBox.Show("You lose unsaved document", "Abort", MessageBoxButtons.OK, MessageBoxIcon.Information); else if (dr == DialogResult.Abort) MessageBox.Show("Oops! else MessageBox.Show("Your System is } still affected!","Ignore",MessageBoxButtons.OK,MessageBoxIcon.Information); your system is attacked severly!", "Abort", MessageBoxButtons.OK, MessageBoxIcon.Information);

Step 8: Double click on the command button Error and enter the following codes. private void button3_Click(object sender, EventArgs e) { MessageBox.Show("Error MessageBoxIcon.Error); } Step 9: Double click on the command button Stop and enter the following codes. private void button6_Click(object sender, EventArgs e) { dr = MessageBox.Show("Save and close all the documents", "Stop", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop); if (dr == DialogResult.Yes) MessageBox.Show("Document is saved successfully", "Yes", MessageBoxButtons.OK, MessageBoxIcon.Information); in the Program", "Error", MessageBoxButtons.OK,

- 58 -

else if (dr == DialogResult.No) MessageBox.Show("Document MessageBoxIcon.Information); else MessageBox.Show("No operation", "Cancel", MessageBoxButtons.OK, MessageBoxIcon.Information); } Step 10: Double click on the command button Exit and enter the following codes. private void button7_Click(object sender, EventArgs e) { this.Close(); } Step 11: Press Ctrl+F5 to run the application. Step 12: Stop the process. SCREEN OUTPUT: Screen shot-1 is not saved", "No", MessageBoxButtons.OK,

Screen shot-2

- 59 -

Screen shot-3

RESULT Thus the above application Retrieving information from message Box has Ex No: 10 executed successfully. been Date: 23/09/11

STOCK MARKET EXCHANGE INFORMATION

- 60 -

AIM: Develop a middleware component for retrieving Stock Market Exchange information using CORBA. ALGORITHM: STEP 1: Start the process. STEP 2: Create the IDL file and save it as stock.idl i) Declare the CORBA IDL module. ii) iii) Declare the interface Declare the operations and

iv) Mapping the IDL to java STEP 3: Create the server method and save it as StockServer.java STEP 4: Create the client method and save it as StockClient..java STEP 5: Compile the StockServer and StockClient as javac StockServer.java StockApp/*.java javac StockClient.java StockApp/*.java STEP 6: Execute the Stock market Application as following below. i) Start orbd start orbd ORBInitialPort 1050 ORBInitialHost localhost ii) Run the StockServer by using start java StockServer ORBInitialPort 1050 ORBInitialHost localhost iii) Run the StockClient by using start java StockClient ORBInitialPort 1050 ORBInitialHost localhost STEP 7: Stop the process.

- 61 -

SOURCE CODE //IDL interface named as stock.idl module StockApp { interface Stock { double input (in double unit,in double rate); }; }; //Server program named as StockServer.java import StockApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; import org.omg.PortableServer.POA; class StockImpl extends StockPOA { private ORB n; public void setORB(ORB j) { n=j; } //implement setORB method public double input(double unit,double no) { return unit*no; } } //create a class StockServer public class StockServer { public static void main(String arg[]) { try { //create and initialize the ORB ORB orb=ORB.init(arg,null); //get reference to rootpoa and activate the POAManager POA rootpoa=POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); //Create Servant and register it with the ORB StockImpl w=new StockImpl();

- 62 -

w.setORB(orb); //get object reference from the servant org.omg.CORBA.Object ref=rootpoa.servant_to_reference(w); Stock href=StockHelper.narrow(ref); //get the root naming context org.omg.CORBA.Object objRef=orb.resolve_initial_references("NameService"); NamingContextExt ncRef=NamingContextExtHelper.narrow(objRef); //bind the object reference in naming String name="p1"; NameComponent path[]=ncRef.to_name(name); ncRef.rebind(path,href); System.out.println("Server Ready and Waiting "); //Wait for invocations from clients. orb.run(); { System.out.println("Error occur"+e); e.printStackTrace(System.out); } } } } catch(Exception e)

//Client program named as StockClient.java import StockApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import java.io.*; public class StockClient { static Stock k; public static void main(String arg[]) { String[ ] uid={"M120","p1190","M890","K345"}; String[ ] p={"Hutch","Infosys","Wipro","Cognizant"}; double[ ] unit={5,6,5,6}; double[ ] noshares={10,4,7,3}; double[ ] total={0,0,0,0}; int ch;

- 63 -

try { //create and initialize the ORB ORB orb=ORB.init(arg,null); //get the root naming context org.omg.CORBA.Object objRef=orb.resolve_initial_references("NameService"); //use NamingContextExt instead of NamingContext.This is the part of the interoperable naming service. NamingContextExt ncRef=NamingContextExtHelper.narrow(objRef); //resolve the object reference in naming String name="p1"; k=StockHelper.narrow(ncRef.resolve_str(name)); for(int i=0;i<4;i++) { } total[i]=k.input(unit[i],noshares[i]); System.out.println("\t\tSTATUS OF NSE"); System.out.println("\t----------------------------------------------------------------"); System.out.println("\tUid CompanyName\tUnit\tNoofshares\tTotal"); System.out.println("\t-----------------------------------------------------------------"); for(int i=0;i<4;i++) { System.out.println(uid[i]+"\t"+p[i]+"\t"+unit[i]+"\t"+noshares[i]+"\t"+total[i]); } System.out.println("\t-----------------------------------------------------------------"); BufferedReader k1=new BufferedReader(new InputStreamReader(System.in)); String c="y"; do { System.out.println("\t\tMenu options"); System.out.println("1.Buy\n"); System.out.println("2.Sell\n"); System.out.println("3.Display\n"); System.out.println("\nEnter your choice:"); ch=Integer.parseInt(k1.readLine()); switch(ch) { case 1: - 64 -

System.out.println("\nSTOCK MARKET EXCHANGE");

System.out.println("Enter your BuyerId:"); String bid=k1.readLine(); System.out.println("Enter company Name"); String co=k1.readLine(); System.out.println("No.of share you want to buy:"); double sh=Double.parseDouble(k1.readLine()); System.out.println("Enter Seller id:"); String sid=k1.readLine(); for(int i=0;i<4;i++) { if(uid[i].equals(bid)) { if(p[i].equals(co)) { noshares[i]+= sh; total[i]=unit[i]*noshares[i]; } } } for(int i=0;i<4;i++) { if(uid[i].equals(sid)) { if(p[i].equals(co)) { noshares[i]-=sh; total[i]=unit[i]*noshares[i]; } }} break; case 2: System.out.println("Enter your Seller Id:"); String sid1=k1.readLine(); System.out.println("Enter company Name"); String co1=k1.readLine(); System.out.println("No.of share you want to sell:"); double sh1=Double.parseDouble(k1.readLine()); System.out.println("Enter Seller id:"); String bid1=k1.readLine(); for(int i=0;i<4;i++) { if(uid[i].equals(sid1)) { if(p[i].equals(co1)) { noshares[i]-= sh1; total[i]=unit[i]*noshares[i]; } } } for(int i=0;i<4;i++) { - 65 -

if(uid[i].equals(bid1)) { if(p[i].equals(co1)) { noshares[i]-=sh1; total[i]=unit[i]*noshares[i]; } } } break; case 3: System.out.println("\t\tSTATUS OF NSE"); System.out.println("\t--------------------------------------------------------"); System.out.println("\tUid\tCompanyName\tUnit\tNoofShares\tTotal"); System.out.println("\t--------------------------------------------------------"); for(int i=0;i<4;i++) { System.out.println(uid[i]+"\t"+p[i]+"\t"+unit[i]); System.out.println ("\t"+noshares[i]+"\t"+total[i]); } break; } System.out.println("Do you want to continue(y/n):"); c=k1.readLine(); }while(c.equals("y")); } catch (Exception e) { System.out.println("Error occur"+e); e.printStackTrace(System.out); } } } SCREEN OUTPUT STOCK MARKET EXCHANGE STATUS OF NSE -----------------------------------------------------------------Uid CompanyName M124 Hutch P1190 Infosys M890 Hutch K345 Infosys Unit Noofshares 5.0 6.0 5.0 6.0 10.0 4.0 7.0 3.0 total 50.0 24.0 35.0 18.0 -------------------------------------------------------------------

------------------------------------------------------------------

- 66 -

Menu Options 1. Buy 2. Sell 3. Display Enter your choice: 1 Enter your Buyer Id: M124 Enter Company Name: Hutch No. of share you want to Buy: 5 Enter Seller Id: 123 Do you want to continue(y/n): y Menu Options 1. Buy 2. Sell 3. Display Enter your choice: 3 STATUS OF NSE ----------------------------------------------------------------------------Uid M124 P1190 M890 K345 Company Name Hutch Infosys Hutch Infosys Unit No of shares 5.0 6.0 5.0 6.0 15.0 4.0 7.0 3.0 total 75.0 24.0 35.0 18.0 -----------------------------------------------------------------------------

Do you want to continue(y/n): n

RESULT Thus the above application Stock Exchange Information using CORBA has been executed successfully.

- 67 -

Ex No: 11 Date: 24/09/11 AIM: To develop a middleware component for retrieving Weather forecast information using CORBA. ALGORITHM: STEP 1: Start the process. STEP 2: Create the IDL file and save it as WeatherApp.idl v) Declare the CORBA IDL module. vi) vii) viii) Declare the interface Declare the operations and Mapping the IDL to java

WEATHER FORECAST INFORMATION

STEP 3: Create the server method and save it as WeatherServer.java STEP 4: Create the client method and save it as WeatherClient..java STEP 5: Compile the WeatherServer and WeatherClient as javac WeatherServer.java StockApp/*.java javac WeatherClient.java StockApp/*.java STEP 6: Execute the Stock market Application as following below. iv) Start orbd start orbd ORBInitialPort 1050 ORBInitialHost localhost v) Run the WeatherServer by using start java WeatherServer ORBInitialPort 1050 ORBInitialHost localhost vi) Run the WeatherClient by using start java WeatherClient ORBInitialPort 1050 ORBInitialHost localhost STEP 7: Stop the process.

- 68 -

SOURCE CODE: //IDL INTERFACE module WeatherApp { interface Weather { void adjusttemp(in double r); double getcurrent(); double getMax(); double getMin(); void call(in double k); oneway void shutdown(); }; }; //CLIENT PROGRAM import WeatherApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; public class WeatherClient { static Weather wt; public static void main(String args[]) { double[][] wr={{-1.5,2.5,4.2,-4.5},{-2.3,-7.8,6.2,-4.7},{4.3,-3.6,5.9,-1.7}}; String[] wc={"Chennai","Mumbai","Delhi","Calcutta"}; int i,j; try { ORB w=ORB.init(args,null); org.omg.CORBA.Object wf=w.resolve_initial_references("NameService"); NamingContextExt ncref=NamingContextExtHelper.narrow(wf); String name="Weather"; wt=WeatherHelper.narrow(ncref.resolve_str(name)); System.out.println("Obtained Handle on Object Server"+wt); System.out.println("\t WEATHER FORECASTING"); System.out.println("\t***********************"); wt.call(20.0); for(i=0;i<3;i++) { - 69 -

System.out.println(wc[i]); System.out.println("*******************"); for(j=0;j<4;j++) wt.adjusttemp(wr[i][j]); System.out.println("\t Max Temp: "+Math.rint(wt.getMax())); System.out.println("\t Min Temp: "+Math.rint(wt.getMin())); System.out.println("\t Current Temp: "+Math.rint(wt.getcurrent())); } wt.shutdown(); } catch(Exception e) { System.out.println(e); } } } //SERVER PROGRAM import WeatherApp.*; import org.omg.CosNaming.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; import org.omg.PortableServer.POA.*; import java.util.Properties; class WeatherImp extends WeatherPOA { private ORB w; private double current,Max,Min; public void setORB(ORB orb_val) { w=orb_val; } public void adjusttemp(double g) { current +=g; if(current>Max) { Max=current; } else if(current<Min) { Min=current; } } public double getMax() { return Max; } public double getMin() { return Min; } public double getcurrent()

- 70 -

{ return current; } public void call(double f) { Min=Max=current=f; } public void shutdown() { w.shutdown(false); } } public class WeatherServer { public static void main(String args[]) { try { ORB w=ORB.init(args,null); POA wpoa=POAHelper.narrow(w.resolve_initial_references("RootPOA")); wpoa.the_POAManager().activate(); WeatherImp w1=new WeatherImp(); w1.setORB(w); org.omg.CORBA.Object ref1=wpoa.servant_to_reference(w1); Weather wref=WeatherHelper.narrow(ref1); org.omg.CORBA.Object wf=w.resolve_initial_references("NameService"); NamingContextExt ncref=NamingContextExtHelper.narrow(wf); String name="Weather"; NameComponent path[]=ncref.to_name(name); ncref.rebind(path,wref); System.out.println("SERVER READY AND WAITING!!"); w.run(); } catch(Exception e) { System.out.println(e); } } }

- 71 -

SCREEN OUTPUT: E:\Weather>idlj Weather.idl E:\Weather>idlj fall Weather.idl E:\Weather>cd WeatherApp E:\Weather\WeatherApp>javac *.java Server: E:\Weather>javac Weather_ser.java E:\Weather>java Weather_ser Hello!!! SERVER READY AND WAITING!! E:\Weather> Client: E:\Weather>javac Weather_clnt.java E:\Weather>java Weather_clnt Obtained Handle on Object Server IOR:000000000000001b49444c3a57656174686572417070 2f576561746865723a312e300000000000010000000000000086000102000000000d313 9322e3136 382e362e3430000005d500000031afabcb0000000020909d99 c40000000 1000000000000000100000008526f6f74504f41000000000800000001000000000 a000000000000020000000100000020000000000001000100000002050100010001002 000010109000000010001010000000026000000020002 WEATHER FORECASTING *********************** Chennai ******************* Max Temp: 25.0 Min Temp: 18.0 Current Temp: 21.0

Mumbai

- 72 -

******************* Max Temp: 25.0 Min Temp: 11.0 Current Temp: 12.0 Delhi ******************* Max Temp: 25.0 Min Temp: 11.0 Current Temp: 17.0 E:\Weather>

RESULT Thus the above application Weather Forecast Information using CORBA has been executed successfully.

- 73 -

You might also like