Professional Documents
Culture Documents
1
INSTRUCTIONS TO BE FOLLOWED IN MAINTAINING THE RECORD BOOK
The Record should be written neatly with ink on the right hand page only. The left hand page being reserved
for diagrams.
1. The date
2. The number and name of the experiment
3. The aim of the experiment
4. Algorithm
5. Program
6. On the left hand side, Flow charts should be designed
7. On the left hand side, Input & Output should be mentioned.
8. Index must be filled in regularly.
9. You must get your record certified by the concerned staff on the very next class after completing the
experiment
10. You must get your record certified by the concerned staff at the end of every semester.
1. You must bring record observations notebook, while coming to the practical class without you may not be
allowed to the practical.
2. Don’t touch the equipment which is not connected with our experiment.
3. When the system /apparatus is issued, you are advised to check their conditions.
4. You should not leave the laboratory without obtaining the signature of the concerned lecturer after completing
the practical
Note:
2
INDEX
1. Single Inheritance
2. Multilevel Inheritance
3. Hierarchial Inheritance
3 Implementing Multiple Inheritance by means of 9-10
Interfaces.
4 String Manipulation : 10-11
1. Alphabetical Ordering of Strings.
2. Frequency count of Words and
Characters in a Text.
LAB CYCLE2
7 Program to write applets to draw various shapes 14-16
square inside a circle
circle inside a square
program to draw a polygon
program to draw a cylinder
program to draw a cube
8 Write a program for handling Mouse Events. 16-19
Mouse entered, Mouse pressed, Mouse released
key event handle.
Program:
Program for method over loading
class A
{
int a,b,c;
void accept(int x)
{
a=x;
System.out.println("a is"+a);
}
void accept(int x,int y)
{
b=x;
c=y;
System.out.println("b is"+b);
System.out.println("c is"+c);
}
}
class ma
{
public static void main(String args[])
{
accept aa=new accept(10,20);
accept aa=new accept(30);
}
}
Program for method over riding
class A
{
int a;
A(int x)
{
a=x;
}
void display()
{
4
System.out.println("a is "+a);
}
}
class B extends a
{
int b,c;
B(int x,int y)
{
b=x;c=y;
}
void display()
{
System.out.println("b is "+b);
System.out.println("c is "+c);
}
class mr
{
public static void main(string args[])
{
A a=new A(10);
B b=new B(20,30);
}
1. Single Inheritance
2. Multilevel Inheritance
3. Hierarchical Inheritance
Program:
Program for single inheritance
class A
{
int a,b;
void display()
{
System.out.println("a is"+a);
System.out.println("b is"+b);
}
}
class B extends A
{
int c;
void accept(int z)
{
c=z;
}
void dis()
{
System.out.println("c is"+c);
}
}
class Inher
{
public static void main(String args[])
{
B bb=new B();
bb.acc(10,20);
bb.accept(30);
bb.display();
bb.dis();
}
}
6
}
}
class B extends A
{
int c;
void acc(int z)
{
c=z;
}
void show()
{
System.out.println("c is:"+c);
}
}
class C extends B
{
int d;
void gets(int w)
{
d=w;
}
void show()
{
System.out.println("d is:"+d);
}
}
class MuInh
{
public static void main(String args[])
{
C cc=new C();
cc.accept(10,20);
cc.acc(30);
cc.gets(40);
cc.show();
}
}
class stud
{
String name;
int num;
7
System.out.println("Enter your number:");
num=Integer.parseInt(in.readLine());
}
void display()
{
System.out.println("Name:"+name);
System.out.println("number:"+num);
}
}
void display()
{
System.out.println("\n");
System.out.println("branch"+branch);
}
}
void display()
{
System.out.println("Name"+name+"number"+num+"total"+total);
}
8
void getdata3() throws IOException
{
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter your percent");
percent=Float.parseFloat(in.readLine());
}
void display()
{
System.out.println("name"+name+"number"+num+"total"+total+"percent"+percent);
}
}
class hirac
{
public static void main(String args[])throws IOException
{
stud st=new stud();
stud1 st1=new stud1();
stud2 st2=new stud2();
stud3 st3=new stud3();
st.getdata();
st1.getdata1();
st2.getdata2();
st3.getdata3();
st.display();
st1.display();
st2.display();
st3.display();
}
}
Program:
class student
{
int rollnumber;
void getNumber(int n)
{
rollnumber=n;
}
void putNumber()
{
9
System.out.println("Rollno:"+rollnumber);
}
}
interface sports
{
float sportwt=6.0F;
void putwt();
}
class multiple
{
public static void main(String args[])
{
Results res=new Results();
res.getNumber(1234);
res.getMarks(27.5F,33.0F);
res.display();
10
}
}
4. String Manipulation:
1. Alphabetical Ordering of Strings.
2. Frequency count of Words and Characters in a Text.
Aim: Program to implement alphabetical ordering of strings, Frequency count of words and characters in a text.
Program:
Program to implement alphabetical ordering of strings
class Stringordering
{
static String name[]={"nodes","delhi","ahmedabad","calcutta","bombay"};
public static void main(String args[])
{
int size=name.length;
String temp=null;
for(int i=0;i<size;i++)
{
for(int j=i+1;j<size;j++)
{
if(name[j].compareTo(name[i])<0)
{
temp=name[i];
name[i]=name[j];
name[j]=temp;
}
}
}
for(int i=0;i<size;i++)
{
System.out.println(name[i]);
}
}
}
class str_manip
{
public static void main(String args[])throws IOException
{
int j=1;
11
StringBuffer str=new StringBuffer("madhuri nallamothu");
System.out.println("original string :"+str);
System.out.println("length of string :"+str.length());
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)==' ')
j++;
}
System.out.println("No.of.words :"+j);
}
}
5. Packages.
Aim:
Program to create the Packages in Java.
Program:
package MyPack;
class account
{
String name;
double bal;
account(String n,double b)
{
name=n;
bal=b;
}
void display()
{
System.out.println("Name\t"+name+"\tin balance\t"+bal);
}
}
class pack
{
public static void main(String args[])
{
account ob[]=new account[3];
ob[0]=new account("madhuri",130.00);
ob[1]=new account("madhu",145.56);
ob[2]=new account("madhuri.n",1200.65);
12
for(int i=0;i<3;i++)
{
ob[i].display();
}
}
}
Program:
class A extends Thread
{
Thread t=new Thread();
13
public void run()
{
for(int k=1;k<=5;k++)
{
System.out.println("it from thread C:k="+k);
if(k==3)
try
{
t.sleep(1000);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
System.out.println("Exit from C");
}
}
class thread
{
public static void main(String args[])
{
A ThreadA=new A();
B ThreadB=new B();
C ThreadC=new C();
Aim: . Program to write applets to draw various shapes-Square inside a circle, Circle inside a square, draw a
polygon, draw a cylinder, Program to draw a cube
14
Program
Program to write applets to draw Square inside a circle
import java.awt.*;
import java.applet.*;
/*<applet code="linerect1"
width=300
height=200>
</applet>*/
public class linerect1 extends Applet
{
public void paint(Graphics g)
{
g.drawOval(20,20,30,30);
g.drawRect(10,10,60,60);
}
}
Program to write applets to draw polygon
import java.awt.*;
import java.applet.*;
/*<applet code="HouseGlass"
width=230
height=210>
</applet>*/
public class HouseGlass extends Applet
{
public void paint(Graphics g)
{
int xpoint[] = {25,10,15,35,40};
int Ypoint[] = {10,30,50,50,30};
int num = 5;
g.drawPolygon(xpoint,Ypoint,num);
15
}
}
Program to write applets to draw cylinder
import java.awt.*;
import java.applet.*;
/*<applet code="Linep" width=200
height=200>
</applet>*/
Aim: A program to handle mouse events – mouse entered, mouse pressed, mouse released and key event handle
16
Program:
Program to handle mouse events – mouse entered, mouse pressed, mouse released
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="MouseEvents" width=300 height=100>
</applet>
*/
public class MouseEvents extends Applet implements MouseListener, MouseMotionListener
{
String msg = " ";
int mouseX = 0, mouseY = 0;
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
mouseX = 0;
mouseY = 10;
msg = "Mouse clicked.";
repaint();
mouseX = 0;
mouseY = 10;
msg = "Mouse entered.";
repaint();
mouseX = 0;
mouseY = 10;
msg = "Mouse exited.";
repaint();
}
public void mousePressed(MouseEvent me)
{
mouseX = me.getX();
17
mouseY = me.getY();
msg = "Down";
repaint();
mouseX = me.getX();
mouseY = me.getY();
msg = "Up";
repaint();
}
Program to handle key events
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="SimpleKey" width=300 height=100>
</applet>
*/
public class SimpleKey extends Applet implements KeyListener
{
String msg = "";
int X = 10, Y = 20;
18
{
addKeyListener(this);
requestFocus();
}
public void keyPressed(KeyEvent ke)
{
showStatus("Key Down");
}
public void keyReleased(KeyEvent ke)
{
showStatus("Key Up");
}
public void keyTyped(KeyEvent ke)
{
msg+=ke.getKeyChar();
repaint();
}
}
9. Program to manipulate lists
i) Lists
ii) Text field
iii) Scroll bars
iv)Text area
v) Menus
Aim: program to manipulate lists-Lists, Text field, Scroll bars, Text area, Menus
Program:
Program to manipulate Lists
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
20
g.drawString("Name: " + name.getText(), 6, 60);
g.drawString("Selected text in name: "+ name.getSelectedText(), 6, 80);
g.drawString("Password: " + pass.getText(), 6, 100);
}
}
Program to manipulate Scroll bars
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="SBDemo" width=300 height=200>
</applet>
*/
public class SBDemo extends Applet
implements AdjustmentListener, MouseMotionListener
{
String msg = "";
Scrollbar vertSB, horzSB;
public void init()
{
int width = Integer.parseInt(getParameter("width"));
int height = Integer.parseInt(getParameter("height"));
vertSB = new Scrollbar(Scrollbar.VERTICAL,0, 1, 0, height);
horzSB = new Scrollbar(Scrollbar.HORIZONTAL,0, 1, 0, width);
add(vertSB);
add(horzSB);
vertSB.addAdjustmentListener(this);
horzSB.addAdjustmentListener(this);
addMouseMotionListener(this);
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
repaint();
}
21
msg += ", Horizontal: " + horzSB.getValue();
g.drawString(msg, 6, 160);
g.drawString("*", horzSB.getValue(),
vertSB.getValue());
}
}
Program to manipulate Text area
import java.awt.*;
import java.applet.*;
public MenuDemo()
{
mb=new MenuBar();
m=new Menu("color");
mi1=new MenuItem("RED");
mi2=new MenuItem("BLUE");
mi1.addActionListener(this);
mi2.addActionListener(this);
setLayout(new FlowLayout());
mb.add(m);
m.add(mi1);
m.add(mi2);
22
setMenuBar(mb);
setSize(400,400);
setVisible(true);
if(ae.getSource()==mi2)
setBackground(Color.blue);
}
public static void main(String args[])
{
new MenuDemo();
}
}
Program:
import java.sql.*;
import java.io.*;
import java.sun.jdbc.odbc.*;
class Department
{
public static void main(String args[]){
try{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
}catch(ClassNotFoundException e1)
{
System.out.println(“error was caught”+e1.getMessage());
}
try{
Connection conn=DriverManager.getConnection(“jdbc:odbc:suni”,”scott”,”tiger”);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(“select * from dept”);
While(rs.next())
{
System.out.println(rs.getInt(1)+rs.getString(2)+rs.getString(3));
}
}catch(SQLException e2)
{
23
System.out.println(“error was caught”+e2.getMessage());
}
}
}
Program
import java.sql.*;
import java.io.*;
import java.sun.jdbc.odbc.*;
class Student
{
public static void main(String args[]){
try{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
}catch(ClassNotFoundException e1)
{
System.out.println(“error was caught”+e1.getMessage());
}
try{
Connection conn=DriverManager.getConnection(“jdbc:odbc:suni”,”scott”,”tiger”);
PreparedStatement psmt=conn.prepareStatement(“insert into std values(?,?,?)”);
psmt.setInt(1,104);
psmt.setString(2,”ddd”);
psmt.setString(3,”pmcs”);
psmt.executeUpdate();
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(“select * from std”);
While(rs.next())
{
System.out.println(rs.getInt(1)+rs.getString(2)+rs.getString(3));
}
}catch(SQLException e2)
{
System.out.println(“error was caught”+e2.getMessage());
}
}
}
24