Tuesday, 18 March 2014

c program for implement paging technique

#include<stdio.h>
int  main()
{
    int lmem,psize,pmem,i,j,k,c[10],str,pno,off;
    int a[20],b[35],ch,page,index,abs,frame;
    printf("\n enter page size::");
    scanf("%d",&psize);
    printf("\nenter logical memory size::");
    scanf("%d",&lmem);
    printf("\n%d",lmem);
    printf("\n enter data::");
    for(i=0;i<lmem;i++)
        scanf("%d",&a[i]);
    for(i=0;i<32;i++)
        b[i]=-1;
    for(i=0;i<lmem/psize;i++)
    {
        printf("\nenter starting location for page::%d",i);
        scanf("%d",&str);
        if(str%4==0)
        {
            c[i]=str/4;
            for(j=str,k=i*4;j<j+psize,k<i*4+psize;j++,k++)
            {
            b[j]=a[k];
            }
        }
        else
                {
                 printf("\n wrong entry for page the page address shud
be multiples of 4");
                }
        }
    printf("\n the page table is::");
    printf("\n page \t\t frame");
    for(i=0;i<lmem/psize;i++)
        printf("\n %d\t %d",i,c[i]);
    printf("enter the pageno and offset\n");
    scanf("%d%d",&pno,&off);
    abs=c[pno]*4+off;
    printf("\n the physical address %d is::%d",b[abs],abs);
    return 0;
}

c program for implementing segmentation in memory using array

#include<stdio.h>
int main()
{
int a[10][10],b[100],i,j,n,x,base,size,seg,off;
printf("Enter the segments count\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the %d size \n",i+1);
scanf("%d",&size);
a[i][0]=size;
printf("Enter the base address\n");
scanf("%d",&base);
a[i][1]=base;

for(j=0;j<size;j++)
        {
        x=0;
        scanf("%d",&x);
//      b[base]=x;
        base++;
        b[base]=x;
        }
}
printf("Enter the segment number and offset value \n");
scanf("%d%d",&seg,&off);
if(off<a[seg][0])
{
int abs=a[seg][1]+off;
printf("the offset is less tha %d",a[seg][0]);
printf("\n %d + %d = %d\n",a[seg][1],off,abs);
printf("the element %d is at %d ",b[abs+1],abs);
}
else
{
printf("ERROr IN LOCATING");
}
}

Monday, 17 March 2014

applet face program

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code="Baby.class" height=500 width=600>
</applet>
*/
public class Baby extends Applet
{
public void paint(Graphics g)
{
Font f1 = new Font("SansSerif",Font.BOLD | Font.ITALIC,35);
g.drawArc(150,100,300,250,0,180);
g.drawArc(150,100,300,320,180,180);
g.setColor(Color.pink);
g.fillArc(130,50,340,290,0,180);
g.setColor(Color.black);
g.setFont(f1);
g.drawString(" BABY" ,230,140);
g.drawLine(150,225,150,260);
g.drawLine(450,225,450,260);
g.drawArc(120,200,60,70,84,180);
g.drawArc(125,225,45,30,84,180);
g.drawArc(420,200,60,70,267,186);
g.drawArc(425,225,50,30,267,186);
for(int i=0;i<=4;i++)
{
g.drawArc(210,205+i,50,20,0,180);
g.drawArc(340,205+i,50,20,0,180);
}
g.fillOval(220,225,30,30);
g.fillOval(350,225,30,30);
g.drawLine(300,250,270,325);
g.drawArc(270,315,50,20,180,180);
g.drawArc(240,310,120,80,200,140);
g.drawLine(250,353,235,377);
g.drawLine(350,353,365,377);
}
}

jdbc java program to access database using MSaccess

import java.sql.*;
import java.io.*;
class JdbcDemo1
{
Connection con;
Statement stmt;
ResultSet rs;
JdbcDemo1()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection( "Jdbc:Odbc:d1", "","");
stmt = con.createStatement();
String sql = "INSERT INTO mm " + "VALUES (97,'muthuma')";
 stmt.executeUpdate(sql);
 sql = "INSERT INTO mm " +  "VALUES (998,'leena')";
 stmt.executeUpdate(sql);
sql="DELETE FROM mm " + "WHERE ID=97";
 stmt.executeUpdate(sql);
sql="UPDATE  mm " + "SET  Nam= 'prem'  WHERE ID in (998)";
 stmt.executeUpdate(sql);
rs = stmt.executeQuery("SELECT * FROM mm");
while (rs.next()) {
int ID = rs.getInt("ID");
String Nam=rs.getString("Nam");
System.out.println("ID:"+ID+"\tNam:"+Nam);
}
}
catch(SQLException e)
{
System.out.println(e);
}
catch(ClassNotFoundException e)
{
System.out.println(e);

}
}
}
class JdbcDemo
{
public static void main(String args[])
{
new JdbcDemo1();
}
}

life cycle of java applet


import java.applet.*; 
import java.awt.*; 
public class life extends Applet 

 String str=""; 

// Born State 

 public void init() 

 { 

 str+="Executing Born / init state "; 

 } 

// Start State 

 public void start() 

 { 

 str+="Executing Start state "; 

 } 

// Stop / Idle State 

 public void stop() 

 { 

 str+="Executing Stop state "; 

 } 
 public void paint(Graphics g) 

 { 

 g.drawString(str,25,100); 

 } 

// Dead / Destroy State 

 public void destroy() 

 { 

 System.out.println("Destroy / Dead is calling..."); 

 System.out.println("Applet is deleted from memory..."); 

 } 

/*<applet code="life.class" height="150" width="150"  align="MIDDLE"> 

 </applet>*/