Professional Documents
Culture Documents
No:1 Date:
Program:
using System; class uop { public int a,b; public uop(int a1,int b1) { a=a1; b=b1; } public void disp(){Console.WriteLine(a);Console.WriteLine(b);} public static uop operator -(uop ob) { ob.a=-ob.a; ob.b=-ob.b; return ob; } } class unaryoperator { public static void Main(string[] args) { uop u=new uop(-10,-10); u.disp(); uop u1=-u; u1.disp(); } }
Execution:
Compilation: Z:\m.tech\iii sem\lab\ex\i ii opoverload>csc unaryoperator.cs Runing Z:\m.tech\iii sem\lab\ex\i ii opoverload>unaryoperator -10 -10 10
Result:
Thus the unary operator was overloaded and used to change the sign of the variables using C#.Net
Staff signature
Program:
using System; class biop { public int real,im; public biop(){} public biop(int r,int i) { real=r; im=i; } public void disp(){Console.WriteLine(real+"+i"+im);} public static biop operator +(biop ob1,biop ob2) { biop b=new biop(); b.real=ob1.real+ob2.real; b.im=ob1.im+ob2.im; return b; } } class binaryoperator { public static void Main(string[] args) { biop b1=new biop(5,5); b1.disp(); biop b2=new biop(2,2); b2.disp(); biop b3=b1+b2; b3.disp(); } }
Result:
Thus the binary operator was overloaded and used as for real& imaginary value displayer using C#.Net
Staff signature
Expt.No:3 Date:
Program:
using System; using System.Collections; class car:IEnumerable { private car[] carr; public string name; public car(string s) {name=s;} public car() { carr=new car[3]; carr[0]=new car("san"); carr[1]=new car("man"); carr[2]=new car("van"); } public IEnumerator GetEnumerator() {return carr.GetEnumerator();} } class enumInterface { public static void Main(string[] args) { car o=new car(); foreach(car c in o) { Console.WriteLine(c.name); } } }
Execution:
Compilation: Z:\m.tech\iii sem\lab\ex\3 enumerable>csc enumInterface.cs Runing Z:\m.tech\iii sem\lab\ex\3 enumerable>enumInterface san man van
Result:
Thus a enumerator was created using IEnumerable interface and the values stored were displayed using C#.Net
Staff signature
Expt.No:4 Date:
Program:
using System; class combo:IComparable { public int id; public string name; public combo(string name1,int x) { name=name1; id=x; } public int CompareTo(object o) { combo temp=(combo) o; if(this.id>temp.id) return (1); if(this.id<temp.id) return (-1); else return (0); } } class icomparable { public static void Main(string[] args) {
Execution:
Compilation Z:\m.tech\iii sem\lab\ex\4 icomparable>csc icomparable.cs Runing Z:\m.tech\iii sem\lab\ex\4 icomparable>icomparable ccc 1 bbb 12 aaa 123
Result:
Thus the IComparable interface was implemented and the object of that class was displayed using C#.Net
Staff signature
Program:
using System; public class one{public int a;} public class two:ICloneable { public int b; public one o=new one(); public two(int a1,int b1) { o.a=a1; b=b1; } public void show(){Console.WriteLine(o.a+" "+b);} public Object Clone() { two t=new two(o.a,b); return t; } } class twoclone
Execution:
Compilation Z:\m.tech\iii sem\lab\ex\56 cloneable>csc twoclone.cs Runing Z:\m.tech\iii sem\lab\ex\56 cloneable>twoclone 12 12 52 15
Result:
Thus a simple program was developed to implement deep clone of object using C#.Net
10
Staff signature
Expt.No:6 Date:
Program:
using System; public class one {public int a;} public class two:ICloneable { public int b; public one o=new one(); public two(int a1,int b1) { o.a=a1; b=b1; } public void show(){Console.WriteLine(o.a+" "+b);} public Object Clone() {
11
Execution:
Compilation: Z:\m.tech\iii sem\lab\ex\56 cloneable>csc tth.cs Runing: Z:\m.tech\iii sem\lab\ex\56 cloneable>tth 12 12 55 52
Result:
Thus a simple program was developed to implement shallow clone of object using C#.Net
12
Staff signature
Expt.No:7 Date:
Program:
using System; using System.Collections; public class Car { private string name; public string Name { get{return name;} set{name=value;} } public Car(string n) {name=n;} 13
class properties { public static void Main(string[] args) { CarCollection c=new CarCollection(); c.Add(new Car("santro")); c.Add(new Car("suzuki")); c.Add(new Car("nano")); c.Add(new Car("azer")); foreach(Car car in c) { Console.WriteLine(car.Name); } Console.WriteLine(c[2].Name); c[2].Name="zen"; Console.WriteLine(c[2].Name); foreach(Car car in c) { Console.WriteLine(car.Name); } } }
14
Execution:
Compilation: Z:\m.tech\iii sem\lab\ex\7properties>csc properties.cs Runing: Z:\m.tech\iii sem\lab\ex\7properties>properties santro suzuki nano azer nano zen santro suzuki zen azer
Result:
15
Staff signature
Expt.No:8(i) Date:
Program:
using System; using System.Collections; class queue1 { public static void Main(string[] args) {
16
Execution:
Compilation Z:\m.tech\iii sem\lab\ex\8 collections>csc queue.cs Runing Z:\m.tech\iii sem\lab\ex\8 collections>queue 55 65 65
17
Result:
Thus a simple program was developed to implement collections using queue using C#.Net
Staff signature
Expt.No:8(ii) Date:
Program:
using System; using System.Collections; class stack { public static void Main(string[] args) 18
Execution:
Compilation Z:\m.tech\iii sem\lab\ex\8 collections>csc stack.cs Runing Z:\m.tech\iii sem\lab\ex\8 collections>stack 40 30 30
19
Result:
Thus a simple program was developed to implement collections using stack using C#.Net
Staff signature
Expt.No:9(i) Date:
Program:
20
Execution:
Compilation Z:\m.tech\iii sem\lab\ex\9.indexer>csc one.cs Runing Z:\m.tech\iii sem\lab\ex\9.indexer>one 0 1 2
21
Result:
Thus a simple program was developed to implement one dimensional indexer using C#.Net
Staff signature
Expt.No:9(ii) Date:
22
Execution:
Compilation Z:\m.tech\iii sem\lab\ex\9.indexer>csc twodemo.cs Runing Z:\m.tech\iii sem\lab\ex\9.indexer>twodemo 0 23
Result:
Thus a simple program was developed to implement two dimensional indexer using C#.Net
Staff signature
Expt.No:10 Date:
Aim:
To develop a simple program to implement single & multilevel inheritance using C#.Net
Program:
using System; class A { public int a; public A(){a=0;} public A(int x){a=x;} public void Display() { Console.WriteLine("Base class A's value is:" + a); } } class B:A { public int b; public B(){b=0;} public B(int x){b=x;} public void Display1() { Console.WriteLine("Derived class B's value is:" + b); } } class C:B { int c; public C(){b=0;} public C(int x,int y,int z){a=x;b=y;c=z;} public void Display2() { Console.WriteLine("Derived class C's value is:" + c); } } class Class1 { public static void Main() { 25
Execution:
Compilation
26
Result:
Thus a simple program was developed to implement the single & multilevel inheritance using C#.Net
Staff signature
27
J2EE and .Net Lab Expt.No:1(i) Date: IMPLEMENTING PROVIDER AND ADAPTER OBJECTS USING ADO.NET Aim:
To access the student database and retrieve its contents using provider and adapter objects of ado.net using C#.Net
Program:
//7 OleDB Sample using System; using System.Data; using System.Data.OleDb; using System.Xml.Serialization; public class MainClass { public static void Main () { // Set Access connection and select strings. // The path to student.MDB must be changed if you build // the sample from the command line: #if USINGPROJECTSYSTEM string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\student.mdb"; #else string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.mdb"; #endif string strAccessSelect = "SELECT * FROM MyTable"; // Create the dataset and add the MyTable table to it: DataSet myDataSet = new DataSet(); OleDbConnection myAccessConn = null; try { myAccessConn = new OleDbConnection(strAccessConn); } catch(Exception ex) { Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message); return;
28
29
30
Execution:
Compilation C:\ado.net>csc oledb.cs Runing C:\ado.net>oledb Found data table MyTable 1 tables in data set 1 tables in data set 2 rows in MyTable table 4 columns in MyTable table Column name[0] is regno, of type System.Int32 Column name[1] is name, of type System.String Column name[2] is mark1, of type System.Int32 Column name[3] is mark2, of type System.Int32 id = 1 Name = san Mark1 = 100 Mark2 = 100 id = 2 Name = vid Mark1 = 100 Mark2 = 100
Result:
Thus the table name, no of rows and entries of the table were accessed using the provider and adapter objects using C#.Net
Staff signature
31
Expt.No:1(ii) Date:
Program:
using System; using System.IO; using System.Data; class ten { public static void Main(string[] args) { try { DataTable t=new DataTable("student"); DataColumn c1=new DataColumn(); c1.ColumnName="id"; c1.DataType=Type.GetType("System.Int32"); c1.AllowDBNull=false; c1.Unique=true; DataColumn c2=new DataColumn(); c2.ColumnName="name"; c2.DataType=Type.GetType("System.String"); t.Columns.Add(c1); t.Columns.Add(c2); DataRow r1=t.NewRow(); r1["id"]=1; r1["name"]="san"; t.Rows.Add(r1); DataRow r2=t.NewRow(); r2["id"]=2; 32
33
34
Execution:
Compilation C:\ado.net>csc ten.cs Runing C:\ado.net>ten enter the id 1 vidtam C:\ado.net>ten enter the id 2 karhin
Result:
Thus the tables student and details were created and related using DataSet student detail and their entries were accessed using C#.Net
35
Expt.No:2(i) Date:
Program:
using System; using System.IO; using System.Text; class exthree { public static void Main(string[] args) { byte[] b=new byte[100]; char[] c=new char[100]; try { FileStream fs=new FileStream(@"D:\a.txt",FileMode.OpenOrCreate); c="hi i am surendran welcome to my page".ToCharArray(); Encoder e=Encoding.UTF8.GetEncoder(); e.GetBytes(c,0,c.Length,b,0,true); fs.Seek(0,SeekOrigin.Begin); fs.Write(b,0,100); } catch(IOException e1){Console.WriteLine(e1.ToString());} }}
36
Execution:
Compilation C:\>csc exthree.cs Runing C:\>exthree a.txt file:
Result:
37
Staff signature
Program:
using System; using System.IO; using System.Text; class extwo { public static void Main(string[] args) { byte[] b=new byte[100]; char[] c=new char[100]; try { FileStream fs=new FileStream(@"D:\a.txt",FileMode.Open); fs.Seek(0,SeekOrigin.Begin); fs.Read(b,0,100); } catch(IOException e){Console.WriteLine(e.ToString());} Decoder d=Encoding.UTF8.GetDecoder(); d.GetChars(b,0,b.Length,c,0); Console.WriteLine(c);
38
Execution:
Compilation C:\>csc extwo.cs Runing C:\>extwo hi i am surendran welcome to my page
Result:
Thus the contents of a.txt file were printed using C#.Net
39
Staff signature
(i)Program:
//simple delegate based event handling using System; delegate void disp(); class classi { static void d1(){Console.WriteLine("A");} static void d2(){Console.WriteLine("B");} static void d3(){Console.WriteLine("C");} public static void Main(string[] args) { disp d; d=new disp(d1); d+=new disp(d2); d+=new disp(d3); d(); }
40
Execution:
Compilation Z:\m.tech\iii sem\lab\ex\II.3.delegates>csc classi.cs Runing Z:\m.tech\iii sem\lab\ex\II.3.delegates>classi A B C
(ii)Program:
//events handled using event handlers using System; using System.IO; delegate void MyEventHandler(); class ce { public event MyEventHandler someevent; public void onsomeevent(){Console.WriteLine("event called");someevent();} } class h1 { public void handler1(){Console.WriteLine("one");} } class h2 { public void handler2(){Console.WriteLine("two");} } class th { public static void Main(string[] args) { ce c=new ce(); h1 h=new h1(); h2 hob=new h2(); c.someevent+=new MyEventHandler(h.handler1); c.someevent+=new MyEventHandler(hob.handler2); 41
Execution:
Compilation Z:\m.tech\iii sem\lab\ex\II.3.delegates>csc th.cs Runing Z:\m.tech\iii sem\lab\ex\II.3.delegates>th event called one two
(iii)Program:
//handling mouse events using System; using System.Windows.Forms; class ex4:Form { public ex4() { Top=40; Left=40; Width=100; Height=500; this.MouseUp+=new MouseEventHandler(OnMouseUp); this.MouseMove+=new MouseEventHandler(OnMouseMove); } public void OnMouseUp(Object o,MouseEventArgs e) {string s=string.Format("current:",e.X,e.Y);MessageBox.Show(s);} public void OnMouseMove(Object o,MouseEventArgs e) {if(e.Button==MouseButtons.Left) MessageBox.Show("left"); if(e.Button==MouseButtons.Right) MessageBox.Show("right"); if(e.Button==MouseButtons.Middle) MessageBox.Show("middle"); }
42
Execution:
Compilation Z:\m.tech\iii sem\lab\ex\II.3.delegates>csc ex4.cs Runing Z:\m.tech\iii sem\lab\ex\II.3.delegates>ex4
Result:
Thus the event handling in .net is demonstrated using delegates using C#.Net
43
Staff signature
Expt.No:4 Date:
Program:
using System; using System.Windows.Forms; class ex6:Form { public ex6() { MainMenu m1=new MainMenu(); MenuItem m2=new MenuItem("File"); MenuItem m3=new MenuItem("open"); MenuItem m4=new MenuItem("close"); m2.MenuItems.Add(m3); m2.MenuItems.Add(m4); m1.MenuItems.Add(m2);
44
Execution:
Compilation Z:\m.tech\iii sem\lab\ex\II.4.controls>csc ex6.cs Runing Z:\m.tech\iii sem\lab\ex\II.4.controls>ex6
45
Result:
Thus a simple application is created using menu control to open and close file using C#.Net
Staff signature
Expt.No:5 Date:
Program:
<%@page language="c#" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <html> <head> <script language="c#" runat="server"> void getData(object o,EventArgs e) { OleDbConnection d=new OleDbConnection(); d.ConnectionString="Provider=Microsoft.JET.OLEDB.4.0;"+"Data Source=c:\\ado.mdb"; d.Open();
46
47
Result:
Thus a simple application was created using ASP.Net
Staff signature
Expt.No:6 Date:
Program:
<%@ WebService Language="C#" Class="FindNo.oddevenclass" %> namespace FindNo { public class oddevenclass { [System.Web.Services.WebMethod] public string odd_check(int x)
48
Explanation:
Folder Name: FindNo Class Name: oddevenclass Function Name: odd_check() (i)Steps to create a Virtual Directory is created Settings ->control panel->Administrative Tools-> Internet Information Services->Double Click->Find Default Web Site icon->Right Click->new->Virtual Directory->click->Next->Alias:FindNo->Dirctory: C:\FindNo->Next->Select Write,Read,Execute,Run,Browse->Finish Virtual Directory is created (ii) load the FindNo.asmx Select Visual Studio 2005->Open Website-> C:\FindNo FindNo.asmx file is loaded (iii)Run the FindNo.asmx file The following page is displayed through asp.net server
49
50
Given x value & then click the Invoke Button the following xml file is displayed
51
Virtual directory:
Namespaces are C# program elements designed to help you organize your programs. good habit
Result:
Thus a simple Web Service was created using .Net
Staff signature
52
Aim:
To display the Life cycle of servlet (ie) State history of Demo Servlet using J2EE
Program:
/* * freak.java */ import java.io.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import javax.servlet.UnavailableException; import java.io.IOException; import java.io.PrintWriter; /** * * @author admin * @version */ public class freak extends HttpServlet { java.util.Vector states; java.util.Random random; int waitinterval; public static final int DEFAULT_WAIT_INTERVAL =10; public freak() { states=new java.util.Vector(); random=new java.util.Random(); waitinterval = DEFAULT_WAIT_INTERVAL; 53
54
55
Output:
56
57
58
Result:
Thus the state history of Demo Servlet was displayed ie life cycle of servlet displayed suceessfully using J2EE.
Staff signature
59
Program:
/* SessionLifeCycleServlet.java */ import java.io.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Date; /** * * @author admin * @version */ public class SessionLifeCycleServlet extends HttpServlet { /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 60
61
62
63
64
65
Result: Thus different sessions are created from a Session Life Cycle Servlet with current date &time using J2EE.
Staff signature
66
Ex No: 3 Date:
Program:
<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%-The taglib directive below imports the JSTL library. If you uncomment it, you must also add the JSTL library to the project. The Add Library... action on Libraries node in Projects view can be used to add the JSTL 1.1 library. --%> <%-<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> --%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%--This is the HTML content--%> <!-comment appears-> <%@ page language="java" import="java.sql.*" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>JSP Page</h1> <% java.util.Date now=new java.util.Date();%> <%= now.getHours()%>: <%= now.getMinutes()%>:<%= now.getSeconds()%> <%-This example uses JSTL, uncomment the taglib directive above. To test, display the page like this: index.jsp?sayHello=true&name=Murphy --%> <%-67
68
Result:
Thus data base data was displayed in JSP with current time using J2EE
69
Ex No: 4 Date:
Program:
cart.java /* * cart.java * * Created on July 31, 2008, 8:58 AM */ import java.io.*; import java.net.*; import java.io.PrintWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * * @author Administrator * @version */ public class cart extends HttpServlet {
70
71
72
73
74
75
76
77
78
Result:
Thus the items was added & displayed in a shopping cart using J2EE
Staff signature
79
Ex No: 5 Date:
Program:
Sentsmtp.java import javax.mail.*; import javax.activation.*; import javax.mail.internet.*; import java.util.*; /** * * @author admin */ public class sentsmtp extends Object { /** Creates a new instance of Main */ /** * @param args the command line arguments */ public static void main(String[] args) { try { Properties props=new Properties(); props.put("mail.transport.protocol","smtp"); props.put("mail.smtp.host"," "); props.put("mail.smtp.port","25"); Session mailsession=Session.getInstance(props); Message msg=new MimeMessage(mailsession); msg.setFrom(new InternetAddress("surendran_mtech_it@yahoo.co.in")); msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("tamilvizhi@g mail.com")); msg.setSentDate(new Date()); msg.setSubject("hi tamil how r u where r u now???"); msg.setText("first mail");
80
Result:
Thus the java mail process was implemented successfully using J2EE
81
Ex No: 6 Date:
Program:
calculator_webservice.java * * To change this template, choose Tools | Templates * and open the template in the editor. */ package calculatorpack; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; /** * * @author Administrator */ @WebService() public class calculator_webservice { /** * Web service operation */
82
83
84
85
86
87
88
Result:
Thus the Web services concept was implemented successfully using J2EE
Staff signature
89
Ex No: 7 Date:
Program: ejbssessionBean.java
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package ejbspack; import javax.ejb.Stateless; /** * * @author admin */ @Stateless public class ejbssessionBean implements ejbssessionRemote { public Integer add(int x, int y) { return x+y; } // Add business logic below. (Right-click in editor and choose // "EJB Methods > Add Business Method" or "Web Service > Add Operation") }
ejbsservlet.java
package ejbspack; import java.io.*; //import java.net.*;
90
index.jsp
<%-Document : index Created on : Aug 11, 2008, 9:03:53 AM Author : admin --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
91
Note:
project Name:ejbs EJB Name: ejbssession Package Name: ejbpack Servlet Name: ejbsservlet
92
93
Result:
Thus the EJB concept was implemented successfully using J2EE
Staff signature
94
First Cycle
..Using C#&.Net
95
Second Cycle
..Using C# & ASP.Net
96
Third Cycle
..Using J2EE
97
Mini Project
98