Wednesday, December 25, 2019

Find shortest word in a string

public class MyClass {
    public static void main(String args[]) {
        String str = "I am Ankit Verma";
        String[] s = str.split(" ");
        String shortest = s[0] ;
        for(String s1:s)
        {
            if(s1.length()<shortest.length())
            {
                shortest = s1;
            }
        }
        System.out.println(shortest);
     }
}

Tuesday, October 3, 2017

10 WHOLE-PART PATTERN


Car.java

public class Car
{
   public CarParts[] parts=new CarParts[10];
   int c=0;
   /**
   @roseuid 56553BC001D7
    */
    public Car()
    {
    System.out.println("Car is initialised and will get assembled now...\n");   
  }
 
   /**
   @roseuid 56553AFA020A
    */
  public void add(CarParts cp)
    {
    parts[c++]=cp;   
    }
   /**
   @roseuid 56553B060252
    */
  public void assemble()
    {
    for(int i=0;i<c;i++)
parts[i].display();
System.out.println("\nCar has been prepared...");   
  }
}


CarParts.java

public interface CarParts 
{
   
  /**
  @roseuid 56553B6E02AD
    */
    public void display();
}
//Source file: C:\\Program Files\\Java\\jdk1.7.0_80\\bin\\Engine.java


public class Engine implements CarParts
{
   
  /**
    @roseuid 56553BC002A4
    */
  public Engine() 
    {
    System.out.println("Engine created");
    }
   
    /**
  @roseuid 56553B980173
  */
  public void display() 
  {
    System.out.println("Engine added");
  }
}

Wheels.java

public class Wheels implements CarParts
{ 
   /**
   @roseuid 56553BC003C9
   */
   public Wheels() 
   {
    System.out.println("Wheels created");
   }
   /**
   @roseuid 56553B9D017F
   */
   public void display() 
   {
    System.out.println("Wheels added");
   }
}


WindShield.java

public class WindShield implements CarParts
{
   /**
   @roseuid 56553BC0032F
   */
   public WindShield() 
   {
    System.out.println("Wind-shield created");
   }
   /**
   @roseuid 56553B910256
   */
   public void display() 
   {
    System.out.println("Wind-shield added");
   }
}


Factory.java


public class Factory
{
   
   /**
   @roseuid 56553BC00113
    */
   public Factory() 
   {
    
   }
   
   /**
   @roseuid 56553AD60084
    */
   public static void main(String[] args) 
   {
    Car car=new Car();
Engine e=new Engine();
WindShield ws=new WindShield();
Wheels w=new Wheels();
car.add(e);
car.add(ws);
car.add(w);
car.assemble();
   }
}

11 MASTER-SLAVE PATTERN









Master.java

public class Master
{
private Resource resource;
private int sk=2;
private Resource res=new Resource();
private Slave[] slave=new Slave[sk];

public Resource getResource() {

return resource;
}

public void setResource(Resource theResource) {
resource = theResource;
}
public void slave()
{
}
        public void run()
{
for(int i=0;i<sk;i++)
slave[i]=new Slave(res);

for(int i=0;i<sk;i++)
slave[i].start();

for(int i=0;i<sk;i++)
{
try
{
slave[i].join();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
finally
{
System.out.println(slave[i].getName()+"--has died");
}
}
System.out.println("Master Exiting now");
}
public void start() {
}
}


Slave.java

public class Slave extends Thread
{
private Resource resource;
private Resource sharedResource;
private Boolean done=false;
public void halt()
{
done=true;
}
public Slave(Resource res)
{
sharedResource=res;
}
protected boolean task()
{
int status=sharedResource.innerStatus();
return(status>7);
}
public Resource getResource() 
{
return resource;
}
public void setResource(Resource theResource) 
{
resource = theResource;
}
public void run() 
{
while(done!=true)
{
done=task();
try
{
Thread.sleep(500);
}
catch(Exception e)
{
}
}
}
}


Resource.java

public class Resource 
{
private TestMaster testmaster;
private int status=0;
public synchronized int innerStatus()
{
int local=status;
System.out.println("Ststus="+local);
local++;
try
{
Thread.sleep(500);
}
catch(Exception e)
{
}
status=local;
System.out.println("New Status="+local);
return status;
}
public TestMaster getTestmaster() 
{
return testmaster;
}

public void setTestmaster(TestMaster theTestmaster) 
{
testmaster = theTestmaster;
}

private Master master;
public Master getMaster() 
{
return master;
}
public void setMaster(Master theMaster) 
{
master = theMaster;
}
private Slave slave;
public Slave getSlave() 
{
return slave;
}
}

TestMaster.java

public class TestMaster 
{
private Resource resource;
public Resource getResource() 
{
return resource;
}
public void setResource(Resource theResource) 
{
resource = theResource;
}
public static void main(String args[]) 
{
Master ms=new Master();
ms.run();
}
}

Tuesday, September 26, 2017

10. Demonstrate arrays of interface types (for runtime polymorphism) with a C# program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IntrDemo {
    public interface Shape
    {
        void area();
    }
        public class circle : Shape
        {
            public void area()
            {
            Console.WriteLine("------Calculating area of CIRCLE--------");
            Console.Write("Enter the radius : ");
            float r = float.Parse(Console.ReadLine());
            Console.WriteLine("Area of Circle" + (3.142) * r * r);
            }
        }
        public class Square : Shape
        {
            public void area()
            {
            Console.WriteLine("------Calculating area of Square--------");
            Console.Write("Enter the length : ");
            float side = float.Parse(Console.ReadLine());
            Console.WriteLine("Area of square" +(side*side));
        }
     }
        class program
        {
            static void Main(string[] args)
            {
            Console.WriteLine("------Calculating area of Square--------");
            Shape[] s = new Shape[2];
            s[0] = new circle();
            s[1] = new Square();
                for (int i = 0; i < s.Length; i++)
                {
                s[i].area();
                Console.ReadLine();
                }
            }
        }
}

9 . WRITE A PROGRAM TO ILLUSTRATE THE USE OF DIFFERENT PROPERTIES IN C#.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Properties
{
class point
{
int getx, gety;
public int x
{
get { return getx; } set {
getx = value; }
}
public int y
{
get { return gety; } set {
gety = value; }
}
}
class Program
{
static void Main(string[] args)
{
point start = new point();
point end = new point();
start.x = 10;
start.y = 20;
end.x = 100;
end.y = 200;
Console.Write( "\npoint 1 : "+ start.x + " " + end.x);
Console.Write("\npoint 2 :"  + start.y + " " + end.y);
Console.ReadLine();
}
}
}

8 WRITE A PROGRAM TO DEMONSTRATE ABSTRACT CLASS AND ABSTRACT METHODS IN C#.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lab8
 {
abstract class person
  {
protected string fname;
protected string lname;
public person(string fn, string ln)
{
fname = fn;
lname = ln;
}
public abstract void display() ;
}

class emp : person
{
public ushort year;
public emp(string fn, string ln, ushort yr): base(fn, ln)
{
year = yr;
}
public override void display()
  {
Console.WriteLine("Employee :" + fname + " " + lname + " " + year);
}
}
class worker : person
 {
    public String company;
             public worker(string fn, string ln, string c) : base(fn, ln)
{
company = c;   
}   
public override void display() { 
Console.WriteLine("Worker :" + fname + " " + lname + " " + company); 
}   
}   
class Program   
{   
         static void Main(string[] args) 
{
Console.WriteLine("**ABSTRACT CLASS  AND ABSTRACT METHODS DEMO **"); 
person p2 = new emp("RAM", "KUMAR", 2012); 
person p3 = new worker("RAM", "KUMAR", "ABC TECH SOLS"); 
p2.display();   
p3.display();   
Console.ReadLine();   
}   
}   
}    

7 Write a program to demonstrate delegates.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _6
{
    public delegate int DelegateSample(int a,int b);
    public class sampleclass
    {
        public int add(int x, int y)
        {
            return x + y;
        }
        public int sub(int x, int y)
        {
            return x - y;
        }
        class program {
            static void Main(String[] args)
            {
                sampleclass s = new sampleclass();
                DelegateSample del = s.add;
                int i = del(10, 20);
                Console.WriteLine("Add result is"+i);
                DelegateSample del1 = s.sub;
                int j = del1(10, 2);
                Console.WriteLine("Sub result is" + j);
                Console.ReadLine();

            }
        }
    }
}

6. DEMONSTRATE USE OF VIRTUAL AND OVERRIDE KEY WORDS IN C# WITH A SIMPLE PROGRAM

using System;
using System.Collections.Generic; using System.Linq;
using System.Text;
namespace VirtualKey
{
class person
{
protected string fname; protected string lname;
public person(string fn, string ln)
{
fname = fn; lname = ln;
}
public virtual void display()
{
Console.WriteLine("Person  :" + fname + " " + lname);
}
}
class emp : person
{
public ushort year;
public emp(string fn, string ln, ushort yr) : base(fn, ln)
{
year = yr;
}
public override void display()
{
Console.WriteLine("Employee :"+fname+" "+lname+" "+year);
}
}
class worker : person
{
public String company;
public worker(string fn, string ln, string c):base(fn, ln)
{
company=c;
}
public override void display()
{
Console.WriteLine("Worker :" + fname + " " + lname + " " +company);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\n\n*** VIRTUAL AND OVERRIDE KEYWORDS DEMO ***");
person p1 = new person("RAVI", "KUMAR"); person p2 = new emp("RAVI", "KUMAR",2012);
person p3 = new worker("RAVI", "KUMAR","XYZ SOLUTIONS"); p1.display();
p2.display();
p3.display();
Console.ReadLine();
}
}
}

Sunday, September 3, 2017

5. Using Try, Catch and Finally blocks write a program in C# to demonstrate error handling.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication14
{
    class Program
    {
        public static void Main(string[] args)
       {
            try
            {
           
                int zero = 0;
                Console.WriteLine("In try block: attempting division by zero");
                int myInt = 1 / zero;
                Console.WriteLine("You never see this message!");
            }
            catch
            {
             
                Console.WriteLine("In catch block: an exception was thrown");
            }
            finally
            {
                Console.WriteLine("In finally block: do any cleaning up here");
                Console.ReadKey();
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplicationavi11
{
    class Lab11
    {
        public static void Main()
        {
            try
            {
                int zero = 0;
                Console.WriteLine("In try block: attempting division by zero");
                int myInt = 1 / zero;
                Console.WriteLine("You never see this message!");
            }
            catch
            {
                Console.WriteLine("In catch block:   an exception was thrown");
            }
            finally
            {
                Console.WriteLine("In finally block:   do any cleaning up here");
            }
            Console.ReadLine();
        }
    }
}

4. Find the sum of all the elements present in a jagged array of 3 inner arrays.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace lab4
{
    public class prgm4
    {
        public static void Main()
        {
            int[][] jag = new int[3][];
            jag[0] = new int[2];
            jag[1] = new int[4];
            jag[2] = new int[3];
            int[] sum = new int[3];
            int result = 0;
            int i, j;
            for (i = 0; i < 3; i++)
                sum[i] = 0;
            Console.WriteLine("Enter the size of the array ");
            for (i = 0; i < jag.Length; i++)
            {
                Console.WriteLine("Enter the values off array " + (i + 1) + " jag:");
                for (j = 0; j < jag[i].Length; j++)
                {
                    jag[i][j] = int.Parse(Console.ReadLine());
                }
            }
            for (i = 0; i < jag.Length; i++)
            {
                for (j = 0; j < jag[i].Length; j++)
                {
                    sum[i] = sum[i] + jag[i][j];
                }
            }
            for (i = 0; i < 3; i++)
                result = result + sum[i];
            Console.WriteLine("The result of individual jags row-wise: ");
            for (i = 0; i < 3; i++)
                Console.Write(sum[i] + "\t");
            Console.WriteLine();
            Console.WriteLine("The final sum of all the elements in the jagged array:" + result);
            Console.Read();
        }
    }
}

Tuesday, August 29, 2017

3. Write a program to demonstrate Operator overloading.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace program
{
 class OpOver
{
int x, y, z; // 3-D coordinates
public OpOver() { x = y = z = 0; }
public OpOver(int i, int j, int k) { x = i; y = j; z = k; }
// Overload binary + for object + object.
public static OpOver operator +(OpOver op1, OpOver op2)
{
OpOver result = new OpOver();
 /* This adds together the coordinates of the two points  and returns the result. */
result.x = op1.x + op2.x;
result.y = op1.y + op2.y;
result.z = op1.z + op2.z;
return result;
}
// Overload binary + for object + int.
public static OpOver operator +(OpOver op1, int op2)
{
OpOver result = new OpOver();
result.x = op1.x + op2;
result.y = op1.y + op2;
result.z = op1.z + op2;
return result;
}
// Show X, Y, Z coordinates.
public void show()
{
Console.WriteLine(x + ", " + y + ", " + z);
}
}
public class Prog3
{
public static void Main()
{
OpOver a = new OpOver(1, 2, 3);
OpOver b = new OpOver(10, 10, 10);
OpOver c = new OpOver();
Console.Write("Here is a: ");
a.show();
Console.WriteLine();
Console.Write("Here is b: ");
b.show();
Console.WriteLine();
c = a + b; // object + object
Console.Write("Result of a + b: ");
c.show();
Console.WriteLine();
c = b + 10; // object + int
Console.Write("Result of b + 10: ");
c.show();
Console.Read();
}
}
}

2. Write a Program in C# to demonstrate boxing and Unboxing.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace boxing
{
class Program
{
static void Main(string[] args)
{
int m = 10;
object a = m;
try
{
Console.WriteLine("Value of m is :" + a);
object n = 20;
int b = (int)n;
Console.WriteLine("Value of n is :" + b);
System.Console.WriteLine("Boxing and unboxing is done");
Console.ReadLine();
}
catch (System.InvalidCastException e)
{
System.Console.WriteLine("Error Incorrect unboxing" + e.Message);
}
}
}
}
//converting from value type to reference type is known as BOXING
//converting from reference type to value type is known as UNBOXING

1. Write a Program in C# to demonstrate Command line arguments processing.

 namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
 {
  System.Console.WriteLine("\nNumber of command line arguments : " + args.Length);
  System.Console.WriteLine("Command line arguments are : \t");
  for (int i = 0; i < args.Length; i++)
  {
  System.Console.WriteLine(args[i]+"\t");
 }
 System.Console.ReadKey(); //system is built in package
  }      
  }
}
 //writeline -- curson will move on to nextline || write -- execte in  current line
//readline --  || readkey --
// try to do without any argument in string and in Main M must be capital

Sunday, July 9, 2017

4. Build a Rails application to accept book information viz. accession number, title, authors, edition and publisher from a web page and store the information in a database and to search for a book with the title specified by the user and to display the search results with proper headings.

After Installing rails application, you have to start the servers both Apache and MySql when you open exe file of rails application, the servers are automatically started

Open a ruby console window

C :\Rails\rails_apps>

Type the following command
Creating Books Database
> mysql -u root

This will now show you mysql> prompt

At mysql prompt type the following

>create database book_development;

>use book_development;

>create table books(id int not null auto_increment,accno varchar(40) not null,title varchar(60) not null,author varchar(60) not null,edition varchar(60) not null,publisher varchar(5) not null,primary key(id));

Creating book Project

Now open another console window type the following command

>rails -d mysql book
>cd book

Creating controller, model and view from database

>ruby script/generate scaffold Book accno:string title:string author:string
edition:string publisher:string

Starting rails server
>ruby script/server

Executing in the web browser
http://localhost:3000/books

Creating main (new) controller for searching book
>ruby script/generate controller main

a controller with a name main will be created..
Opening main controller program
>edit app\controllers\main_controller.rb

Create two views welcome and result

class MainController < ApplicationController
def welcome
@num_books = Book.count
end
def result
@titlename = params[:title]
@bookz = Book.find(:all, :conditions => "title = #{@titlename}")
end
end

Create Result view file
>notepad app\views\main\result.rhtml
<html>
<title> Welcome template for books </title>
<body>
<p> Entered book title is <%= @titlename %> </p>
<table border=1>
<tr><th>Book Id</th> <th>Accesion Number</th><th>Book
Title</th><th>Author</th> <th>Edition </th> <th>Publisher</th></tr>
<% @names.each do |bk|
@id = bk.id
@accno = bk.accno
@title = bk.title
@author = bk.author
@edition = bk.edition
@publisher = bk.publisher%>
<tr>
<td> <%= @id %></td>
<td><%= @accno %> </td>
<td><%= @title %></td>
<td> <%= @author %></td>
<td><%= @edition %></td>
<td> <%= @publisher %></td>
</tr>
<% end %>
</table>
</form></body></html>

Create Welcome view file

>notepad app\views\main\welcome.rhtml
<html>
<title> Welcome template for books </title>
<body>
<p> Total number of books = <%= @num_books %> </p>
<form action = "result" >
Enter Searching Element: <input type="text" name="title" />
<input type=submit value="Search" />
</form></body></html>

Starting Rails Server
ruby script/server

Executing in the web browser
http://localhost:3000/main/welcome

3.Write a PHP program to read student data from an XML file and store into the MySQL database. Retrieve and display using SEARCH function.

lab3.xml

<?xml version="1.0" ?>
<student>
<stud>
<name>BBBB</name>
<usn>1234</usn>
</stud>
<stud>
<name>CCCC</name>
<usn>4567</usn>
</stud>
</student>

lab3.html

<html>
<body>
<center>
<table width="50%" border="2"><tr>
<form action="http://localhost/lab3.php">
<tr><th> ENTER NAME TO SEARCH </th></tr><br/>
<td align="center"><br/>Name: <input type="text" name="name"><br /><br/>
submit: <input type="submit"><br/><br/></td>
</form></tr>
</body>
</html>

lab3.php

<?php
$link=mysqli_connect("localhost","root","","test");
if(!$link)
{
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
$name=$_GET['name'];
$studs=simplexml_load_file("http://localhost/lab3.xml");
foreach($studs as $stud)
{
$name = $stud->name;
$usn = $stud->usn;
mysqli_query($link,"insert into stud3 values('$name','$usn')");
}
$name=$_GET['name'];
$res=mysqli_query($link,"select * from stud3 where name='$name'");
if(mysqli_num_rows($res)==0)
{
echo "$name doesn't exist in the table";
}
else
{
echo "<table border='1' align=center width=60%>";
echo "<tr><td width=15% align=center>NAME</td><td width=15%
align=center>USN</td></tr>";
while($arr=mysqli_fetch_row($res))
echo "<tr><td>$arr[0]</td><td>$arr[1]</td></tr>";
echo "</table>";
}
?>

2. Create a XHTML form with Name, Address Line 1, Address Line 2, and Email text fields. On submitting, store the values in MySQL table. Retrieve and display the data based on Name.

>create database stud;
>use stud;
>create table info(name varchar(40), add1 varchar(40), add2 varchar(40),
email varchar(50));
>desc info;

lab2.html

<html>
<body>
<center>
<table width="50%" border="2"><tr>
<form action="http://localhost/insert.php">
<tr><th> ENTER AGE INFORMATION </th></tr><br/>
<td align="center"><br/>Name: <input type="text" name="name"><br
/><br/>
add1: <input type="text" name="add1"><br /><br/>
add2: <input type="text" name="add2"><br /><br/>
email: <input type="text" name="email"><br /><br/>
submit: <input type="submit"><br/><br/></td>
</form></tr>
<tr><form action="http://localhost/search.php">
<tr><th> ENTER NAME TO BE SEARCHED AND DISPLAY ITS DETAILS</th></tr><br/>
<td align="center"><br/>Name: <input type="text" name="name"><br
/><br/>
submit: <input type="submit"><br/><br/></td>
</form></tr>
</body>
</html>

insert.php


<?php
$link=mysqli_connect("localhost","root","","stud");
if(!$link)
{
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
$name=$_GET['name'];
$add1=$_GET['add1'];
$add2=$_GET['add2'];
$email=$_GET['email'];
echo "hello " .$name;
echo " INSERTED SUCCESSFULLY<br/><br/>";
$query="insert into info values('$name','$add1','$add2','$email')";
mysqli_query($link,$query) or die(mysql_error());
$res=mysqli_query($link,"select * from info");
echo "<table border='1' align=center width=60%>";
echo "<tr><td width=15% align=center>NAME</td><td width=15%
align=center>ADDRESS1</td><td width=15% align=center>ADDRESS2</td><td
width=15% align=center>EMAIL ID</td></tr>";
while($arr=mysqli_fetch_row($res))
echo
"<tr><td>$arr[0]</td><td>$arr[1]</td><td>$arr[2]</td><td>$arr[3]</td></tr>"
;
echo "</table>";
?>



search.php

<?php
$link=mysqli_connect("localhost","root","","stud");
if(!$link)
{
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
$name=$_GET['name'];
$res=mysqli_query($link,"select * from info where name='$name'");
if(mysqli_num_rows($res)==0)
{
echo "$name doesn't exist";
}
else
{
echo "<table border='1' align=center width=60%>";
echo "<tr><td width=15% align=center>NAME</td><td width=15%
align=center>ADDRESS1</td><td width=15% align=center>ADDRESS2</td><td
width=15% align=center>EMAIL ID</td></tr>";
while($arr=mysqli_fetch_row($res))
echo
"<tr><td>$arr[0]</td><td>$arr[1]</td><td>$arr[2]</td><td>$arr[3]</td><
/tr>";
echo "</table>";
}
?>

1.Write a Perl program to insert name and age information entered by the user into a table created using MySQL and to display the current contents of this table.

Open the terminal window, you will get terminal prompt. Enter into the
super user with the following username and password. You will get root
prompt.
Username: su
Password:root123
 Change into mysql with the following command
>mysql
>create database web;
>show databases;
>use web;
>create table age_info(nam varchar(40), age int(11));
>desc age_info;
 Open another terminal window
>chmod 777 /var/www/cgi-bin
>chmod 777 /var/www/html

lab1.html

<html>
<body>
<center><br/><br/>
<table width="50%" border="2"><tr>
<form action="http://localhost/cgi-bin/p1.pl" method="post">
<tr><th> ENTER AGE INFORMATION </th></tr>
<h3>
<td align="center"><br/>Enter your name :<input type="text"
name="nam"><br><br/>
Enter your age :<input type="text" name="age"><br><br/><br/>
click here to send :<input type="submit" value="Send"><br><br/></td>
</h3>
</form></tr>
</table>
</center>
</body>
</html>

l1.pl

#!/usr/bin/perl
use strict;
use CGI':standard';
use DBI;
print header();
print start_html(-title=>"database",-bgcolor=>"#F0F8FF",-text=>"green");
my $nam=param('nam');
my $age=param('age');
my $db=DBI->connect('DBI:mysql:web','root',"") or die "cannot
connect:".DBI->errstr();
my $query=$db->prepare("insert into age_info values('$nam','$age')");
$query->execute();
my $query=$db->prepare("select * from age_info");
$query->execute();
print "<center>";
print "<table width=20% border=2>";
print "<tr><b>STUDENT AGE INFORMATION</b></tr><br/>";
print "<tr><td align=center width=15%><b>NAME</b></td> <td align=center
width=5%><b>AGE</b></td></tr><BR/>";
while(($nam,$age)=$query->fetchrow())
{
print "<tr><td>$nam</td><td>$age</td></tr>";
}
print "</center>";
$query->finish();
$db->disconnect();
print end_html;
exit(0);

Steps to be followed

Load the fedora operating system with the username and password.
For example
Username: fedora
Password: fedora
 Open system menu, click on Administration a submenu will open click on
the service entry. It will open service configuration window.
 Enable and start httpd service and mysqld service entries.
 To open the terminal, select Application menu click on system tools it
will open a submenu. Click on Terminal entry it will open terminal
window.
 In the terminal window, you will get terminal prompt. Enter into the
super user with the following username and password. You will get root
prompt.
Username: su
Password:root1234
 Change the file permission mode using chmod 777 command before
execution of program for the following folders,
>chmod 777 /var/www/cgi-bin
>chmod 777 /var/www/html
 Change into mysql with the following command
>mysql
mysql> show databases;
(use any of the databases available or create a new database )
mysql>create database databasename
mysql>use databasename
mysql>show tables
If tables are not available create a new table by the following
query statement
Create table tablename ( attribute datatypes…..)
 Store your html file under var/www/html and perl or PHP file in cgibin
folder.

13. An EJB application that demonstrates persistence (with appropriate business logic).

Step 1: Creation of Project Application
1. File -> New Project -> Java EE -> Enterprise Application -> click next -> Give name for
project (ex: employee -> set Java EE version as Java EE 5 -> Finish.
2. At the end of creation you can see three modules generated.
Step 2: Create database
1. Select services-> Databases ->right click JavaDB ->create database ->right click
jdbc:derby://….. and connect
Step 3: Creation of Entity Bean
1. Right click on projects ejb module -> new -> Entity class -> Give class name and
package -> click next -> Select data source with your database -> Finish.
2. Change AUTO to IDENTITY and add the following code
String name;
int salary;
3. Select the variables -> right click over the selection -> insert code -> Getter and Setter…
-> select all -> Generate. You can see getter and setter method generated.
Step 4: Creation of Session bean for Entity Class
1. Right click on projects ejb module -> new -> Other -> Enterprise Java beans -> Session
bean for entity classes -> click Add all -> click next -> select local.
Step 5: Creating Servlet file
1. Right click on project war module -> new -> servlet -> Give name for servlet and
package -> next -> finish.
2. Inside the class definition -> Right click -> Insert code -> call enterprise bean -> select
your entity class( ex: EmployeeFacade) -> click ok.
3. Inside processRequest method add the following code,
employee dan=new employee();
dan.setName(request.getParameter("name"));
dan.setSalary(Integer.parseInt(request.getParameter("salary")));
empFacade.create(dan);
4. Left click on the error of first line code -> Add import (for your entity class).
Step 6: Creating jsp file
1. Change the code in index.jsp with your code.
2. Your code should produce two label and 2 text boxes and make sure that mapping servlet
with jsp file done correctly.
(<form action="EmployeeServlet">
Name: <input type="text" name="name" value="">
<br>
Salary: <input type="text" name="salary" value="">
<br><br>
<input type="submit" value="submit">
</form>)
Step 7: Executing the project
1. Right click on Application module -> Clean and bulid -> Right click on Application
module -> Deploy.
2. Under services window -> right click on glassfish server -> start the server -> right click
on glassfish server -> view admin console -> Applications -> click on entity bean class
name -> Launch -> click on first link -> Enter data and submit->
3. You can see the data on database by -> right click on your database -> refresh -> expand
your table -> view data.

12. An EJB application that demonstrates MDB (with appropriate business logic).

Services->glassfishserver3.1->right click start->right click view admin console->JMS Resource-
>Click on Connection Factories->New->
Pool Name: jms/queue -> Resource Type: javax.jms.QueueConnectionFactory
Click on Destination Resources -> New ->
JNDI Name: jms/dest -> Resource Type: javax.jms.Queue minimize the window
File -> NewProject -> Java EE -> EnterpriseApplication -> next -> Java EE Version: select Java
EE 5 ->
Check Create EJB module and Web Application module -> finish
In EJB Module
Right click EJB module -> select new message driven bean -> give EJB Name as MyBean and
package name as com -> Select server destinations as jms/dest
Type the following code in the method onMessage()
TextMessage tmsg=null;
tmsg=(TextMessage)message;
System.out.println(tmsg.getText()); /*Left click on error indicator and select surround statement
with try catch*/
In war Module
Select index.jsp file and type the following code inside body tag
<form action="NewServlet">
<table border="1">
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Enter message</td>
<td><input type="text" name="msg" value="" /></td>
</tr>
</tbody>
</table>
<input type="submit" value="submit" />
</form>
Right Click on war module -> New -> Servlet -> write servlet name and package name -> finish
In NewServlet before try block of processRequest() method ->right click select insert code -
>Select send JMS message ->Connection factory : jms/queue
Before try block of processRequest type
String str=request.getParameter("msg");
sendJMSMessageToDest(str); /*Left click on error indicator and select surround statement with
try catch*/
clean and build application
deploy EJB module
In glass fish server select Applications click deployed file
Run war file