You are on page 1of 58

SREE SANKARA VIDYAPEETOM COLLEGE

Valayanchirangara, Perumbavoor-683556
(Affiliated to Mahatma Gandhi University, NAAC Re-Accredited at ‘A’ Level)

Record of Practical Work in


SOFTWARE LAB V - JAVA PROGRAMMING USING LINUX .

B.Sc. COMPUTER SCIENCE

Name ABHINAV K BINOY Semester V


. University Reg. No 190021030106 Year of Study
2021-2022 .

SREE SANKARA VIDYAPEETOM COLLEGE


Valayanchirangara, Perumbavoor-683556
(Affiliated to Mahatma Gandhi University, NAAC Re-Accredited at ‘A’ Level)

Record of Practical Work in


SOFTWARE LAB V - JAVA PROGRAMMING USING LINUX.

B.Sc. COMPUTER SCIENCE

Name ABHINAV K BINOY Semester V


. University Reg. No 190021030106 Year of Study
2021-2022 .

Certified that bonafide record of work done by the candidate

Ambili M S Dr.
Manusankar C
Faculty in Charge Head of
the Department

External Examiner Internal


Examiner
SL. No. NAME OF EXPERIMENT DATE PAGE No. INITIAL OF
TEACHER
1 USE OF CONSTRUCTORS 22/11/2021 1
2 USE OF COMMAND LINE ARGUEMENT 22/11/2021 4
3 KEYBOARD READING METHOD 24/11/2021 7
4 KEYBOARD READING METHOD & 24/11/2021 10
PERFORMING OPERATIONS
5 METHOD OVERLOADING 25/11/2021 13
6 CONSTRUCTOR OVERLOADING 25/11/2021 17
7 CREATE A PACKAGE 29/11/2021 21
8 INHERITANCE 01/12/2021 24
9 METHOD OVERRIDING 03/12/2021 27
10 EXCEPTION HANDLING 06/12/2021 29
11 USAGE OF THREATS 08/12/2021 32
12 CREATION OF GUI 10/12/2021 35
13 ACTION EVENT HANDLING 13/12/2021 38
14 WINDOW EVENT HANDLING 13/12/2021 41
15 ITEM EVENT HANDLING 15/12/2021 44
16 USE OF APPLETS 17/12/2021 47
17 PARAMETERIZED APPLETS 03/01/2022 49
18 JDBC 05/01/2022 51
Page | 1

1. USE OF CONSTRUCTORS
Date: 22/11/2021

AIM: Write a java program to demonstrate use of constructors to initialize values to


member variables in a class and to display them

PROGRAM
import java.util.*;

class employee

int empno;

float salary;

String name;

employee()

empno=1001;

salary=100000;

name="devan";

void display()

System.out.println("EmpNo : "+empno);

System.out.println("Name : "+name);

System.out.println("Salary : "+salary);

employee(int empno,String type,float salary)

this();

System.out.println("EmpNo : "+empno);

System.out.println("Name : "+type);
Page | 2

System.out.println("Salary : "+salary);

class main extends employee

public static void main(String[] args)

employee emp=new employee(1002,"aakash",100000);

employee emp1=new employee();

emp1.display();

}
Page | 3

OUTPUT

EmpNo: 1002

Name : aakash

Salary : 10000.00

EmpNo: 1001

Name : devan

Salary : 10000.00
Page | 4

2. USE OF COMMAND LINE ARGUEMENT


Date: 22/11/2021

AIM: Write a java program to demonstrate use of command line arguments

PROGRAM
class student2

int clno;

String studname;

int engmark,mathsmark,totalmark;

student2(int a,String b,int c,int d)

clno=a;

studname=b;

engmark=c;

mathsmark=d;

totalmark=c+d;

void display()

System.out.println("The details of the student are : ");

System.out.println (clno+" "+studname+" "+engmark+" "+mathsmark+" "+totalmark);

public static void main(String args[])

if(args.length>3)

{
Page | 5

student2 st1=new
student2(Integer.parseInt(args[0]),args[1],Integer.parseInt(args[2]),Integer.parseInt(args[3]));

st1.display();

else

System.out.println("Reexecute by providing 4 arguments");

}
Page | 6

OUTPUT
The details of the student are :

101 aakash 50 50 100


Page | 7

3. KEYBOARD READING METHOD


Date: 24/11/2021

AIM: Write a java program to demonstrate keyboard reading method

PROGRAM
import java.util.*;

import java.io.InputStreamReader;

import java.io.IOException;

import java.io.BufferedReader;

class student

int clno;

String name;

int mark;

void input(int a,String b,int c)

clno=a;name=b;mark=c;

void display()

System.out.println(clno+"\t"+name+"\t"+mark);

public static void main(String args[])

int a1,c1,i;

String b1;
Page | 8

student s[]=new student[10];

System.out.println("Enter details(ClassNo,Name and Mark)of 3 students:");

InputStreamReader i1=new InputStreamReader(System.in);

BufferedReader b=new BufferedReader(i1);

for(i=0;i<3;i++)

try

a1=Integer.parseInt(b.readLine());

b1=b.readLine();

c1=Integer.parseInt(b.readLine());

s[i]=new student();

s[i].input(a1,b1,c1);

catch(Exception tt)

System.out.println(tt);

System.out.println("ClassNo\tName\tMark");

for(i=0;i<3;i++)

s[i].display();

}
Page | 9

OUTPUT
Enter details (ClassNo,Name and Mark) of 3 students :

101

aakash

100

102

abhinav

100

103

adhilsha

100

ClassNo Name Mark

101 aakash 100

102 abhinav 100

103 adhilsha 100


Page | 10

4.KEYBOARD READING METHOD&PERFORMING


OPERATIONS
Date: 24/11/2021

AIM: Write a java program to demonstrate keyboard reading method and performing
operations

PROGRAM
import java.util.*;

import java.io.*;

class student1

int clno;

String name;

int marks;

void input(int a,String b,int c)

clno=a;name=b;marks=c;

void display()

System.out.println(clno+"\t"+name+"\t"+marks);

public static void main(String args[])

int m=0;

int temp=0;

int a1,c1,i;
Page | 11

String b1;

student1 s[]=new student1[10];

System.out.println("Enter details(ClassNo,Name and Mark)of 3 students");

InputStreamReader i1=new InputStreamReader(System.in);

BufferedReader b=new BufferedReader(i1);

for(i=0;i<3;i++)

try

a1=Integer.parseInt(b.readLine());

b1=b.readLine();

c1=Integer.parseInt(b.readLine());

s[i]=new student1();

s[i].input(a1,b1,c1);

if(c1>m)

m=c1;

temp=i;

catch(Exception tt)

System.out.println(tt);

System.out.println("Top Score");

s[temp].display();

}
Page | 12

OUTPUT
Enter details (ClassNo, Name and Mark) of 3 students :

101

aaksah

100

102

abhinav

98

103

adhilsha

96

Top Score

101 aakash 100


Page | 13

5. METHOD OVERLOADING
Date : 25/11/2021

AIM: Write a java program to demonstrate method overloading

PROGRAM
import java.util.*;

import java.io.*;

class areaof

int a,b;

float c,d;

double ans;

void area(int a)

ans=3.14*a*a;

System.out.println("Area of Circle = "+ans);

void area(int a,int b)

ans=a*b;

System.out.println("Area of Rectangle = "+ans);

void area(float c,float d)

ans=c*d*0.5;

System.out.println("Area of Triangle = "+ans);


Page | 14

class mains extends areaof

public static void main(String args[])

int n;

int y=1;

Scanner sc=new Scanner(System.in);

while(y==1)

System.out.println("1.Area of circle\n2.Area of Rectangle\n3.Area of triangle\nEnter your choice : ");

n=sc.nextInt();

areaof ar=new areaof();

switch(n)

case 1:System.out.println("Enter the Radius : ");

int a=sc.nextInt();

ar.area(a);

break;

case 2:System.out.println("Enter the Length and Breadth : ");

int c=sc.nextInt();

int b=sc.nextInt();

ar.area(c,b);

break;

case 3:System.out.println("Enter the Base and Height : ");

float e=sc.nextFloat();

float f=sc.nextFloat();

ar.area(e,f);

break;

}
Page | 15

System.out.println("Do you Want to Continue ? ");

y=sc.nextInt();

}}

OUTPUT
1.Area of circle

2.Area of Rectangle

3.Area of triangle

Enter your choice :

Enter the Radius :

Area of Circle = 50.26

Do you want to continue?

1.Area of circle

2.Area of Rectangle

3.Area of triangle

Enter your choice :

Enter the length and breadth :

Area of Rectangle = 8.0

Do you want to continue?

1.Area of circle

2.Area of Rectangle

3.Area of triangle

Enter your choice :


Page | 16

Enter the base and height :

Area of triangle = 4.0

Do you want to continue?

0
Page | 17

6. CONSTRUCTOR OVERRIDING
Date: 25/11/2021

AIM: write a java program to familiarize constructor overriding

PROGRAM
import java.util.*;

import java.io.*;

class area

int a,b;

float c,d;

double ans;

area(int a)

ans=3.14*a*a;

System.out.println("Area of Circle = "+ans);

area(int a,int b)

ans=a*b;

System.out.println("Area of Rectangle = "+ans);

area(float c,float d)

{
Page | 18

ans=c*d*0.5;

System.out.println("Area of Triangle = "+ans);

class maina

public static void main(String args[])

int n;

int y=1;

Scanner sc=new Scanner(System.in);

while(y==1)

System.out.println("1.Area of circle\n2.Area of Rectangle\n3.Area of triangle\nEnter your choice : ");

n=sc.nextInt();

switch(n)

case 1:System.out.println("Enter the Radius : ");

int a=sc.nextInt();

area ar=new area(a);

break;

case 2:System.out.println("Enter the Length and Breadth : ");

int c=sc.nextInt();

int b=sc.nextInt();

area am=new area(c,b);

break;

case 3:System.out.println("Enter the Base and Height : ");

float e=sc.nextFloat();

float f=sc.nextFloat();

area an= new area(e,f);

break;
Page | 19

System.out.println("Do you Want to Continue ? ");

y=sc.nextInt();

OUTPUT
1.Area of circle

2.Area of Rectangle

3.Area of triangle

Enter your choice :

Enter the Radius :

Area of Circle = 50.26

Do you want to continue?

1.Area of circle

2.Area of Rectangle

3.Area of triangle

Enter your choice :

Enter the length and breadth :

Area of Rectangle = 8.0

Do you want to continue?

1.Area of circle

2.Area of Rectangle
Page | 20

3.Area of triangle

Enter your choice :

Enter the base and height :

Area of triangle = 4.0

Do you want to continue?

0
Page | 21

7.CREATE A PACKAGE
Date: 29/11/2021

AIM: Write a java program to create a package and use it in another program

PROGRAM
import mypack.*;

class six

public static void main(String args[])

five f=new five();

f.display();

f.display1();

seven s=new seven();

s.display();

s.display1();

Five.java

package mypack;

public class five

public void display()


Page | 22

System.out.println("i belongs to five");

public void display1()

System.out.println("i also belongs to five");

Seven.java

package mypack;

public class five

public void display()

System.out.println("i belongs to five");

public void display1()

System.out.println("i also belongs to five");

}
Page | 23

OUTPUT
I belongs to five

I also belongs to five

I belongs to seven

I also belongs to seven


Page | 24

8. INHERITANCE
Date: 01/12/2021

AIM: Write a java program to demonstrate inheritance

PROGRAM
import java.util.*;

class parent

public void putdatap()

System.out.println("This is parent class");

class child extends parent

void putdatac()

System.out.println("This is child class");

class newq extends child

{
Page | 25

void putdatan()

System.out.println("This is new class");

class mainf extends newq

public static void main(String args[])

parent p= new parent();

child c= new child();

newq n= new newq();

p.putdatap();

c.putdatac();

c.putdatap();

n.putdatap();

n.putdatac();

n.putdatan();

}
Page | 26

OUTPUT
This is parent class

This is child class

This is parent class

This is parent class

This is child class

This is a new class


Page | 27

9. METHOD OVERRIDING
Date: 03/12/2021

AIM: Write a java program to demonstrate method overriding

PROGRAM
class eight

void display()

System.out.println("Hello I am from derived class");

class nine extends eight

void display()

System.out.println("Hello I belong to derived class ");

public static void main(String args[])

nine n=new nine();


Page | 28

n.display();

OUTPUT
Hello I belong to derived class
Page | 29

10. EXCEPTION HANDLING


Date: 06/12/2021

AIM: Write a java program to familiarize exception handling

PROGRAM
class ten

int a,b,c;

ten(int a1,int a2)

a=a1;

b=a2;

try

c=a/b;

System.out.println("Quotient is "+c);

catch(ArithmeticException e)

System.out.println("Denominator cannot be zero");

System.out.println(e);
Page | 30

finally

System.out.println("Have a good day");

public static void main(String args[])

if(args.length!=2)

System.out.println("Reexecute with two arguments");

else

int b1=Integer.parseInt(args[0]);

int b2=Integer.parseInt(args[1]);

ten tt=new ten(b1,b2);

}
Page | 31

OUTPUT
Reexecute with two arguments

34

Quotient is 0

Have a good day


Page | 32

11.USAGE OF THREATS
Date: 08/12/2021

AIM: Write a java program to demonstrate the usage of threats

PROGRAM
class eight1 extends Thread

Thread t1,t2;

int i;

eight1()

t1=new Thread(this);

t2=new Thread(this);

t1.start();

t2.start();

public void run()

try

{
Page | 33

for(i=0;i<5;i++)

if(Thread.currentThread()==t1)

System.out.println("hai everyone");

t1.sleep(5);

else

System.out.println("my name is astro");

t2.sleep(10);

catch(Exception h){}

public static void main(String args[])

eight1 ty=new eight1();

}
Page | 34

OUTPUT
hai everyone

my name is astro

hai everyone

hai everyone

my name is astro

hai everyone
Page | 35

12.CREATION OF GUI
Date: 10/12/2021

AIM: Write a java program to create a GUI

PROGRAM
import java.awt.*;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.awt.event.*;

class twelve extends WindowAdapter

Frame f1;

Panel p1;

Label l1,l2,l3;

TextField t1,t2,t3;

Button b1,b2;

twelve()

{
Page | 36

f1=new Frame("Registration form");

f1.addWindowListener(this);

p1=new Panel();

l1=new Label("Name please");

l2=new Label("college name");

l3=new Label("Emailaddress");

t1=new TextField(10);

t2=new TextField(10);

t3=new TextField(10);

b1=new Button("Submit");

b2=new Button("Reset");

p1.add(l1);

p1.add(t1);

p1.add(l2);

p1.add(t2);

p1.add(l3);

p1.add(t3);

p1.add(b1);

p1.add(b2);

f1.add(p1);

f1.setSize(300,300);

f1.setVisible(true);

public void windowClosing(WindowEvent e)

System.exit(0);

public static void main(String args[])

twelve tt=new twelve();

}
Page | 37

OUTPUT
Page | 38

13. ACTION EVENT HANDLING


Date: 13/12/2021

AIM: Write a java program to demonstrate action event handling

PROGRAM
import java.awt.*;

import java.awt.event.*;

class thirteen

Frame f1;

Panel p1;

//Textfield t1,t2;

Button b1,b2;

thirteen()

Frame f1=new Frame();

Panel p1=new Panel();

TextField t1=new TextField(10);


Page | 39

TextField t2=new TextField(10);

Button b1=new Button("Swap");

Button b2=new Button("Exit");

p1.add(t1);

p1.add(t2);

p1.add(b1);

p1.add(b2);

f1.add(p1);

f1.setSize(300,300);

f1.setVisible(true);

b1.addActionListener(new ActionListener()

public void actionPerformed(ActionEvent e)

String s1=t1.getText();

String s2=t2.getText();

t1.setText(s2);

t2.setText(s1);

});

b2.addActionListener(new ActionListener()

public void actionPerformed(ActionEvent e)

System.exit(0);

});

public static void main(String args[])

thirteen tt=new thirteen();


Page | 40

OUTPUT
Page | 41

14. WINDOW EVENT HANDLING


Date: 13/12/2021

AIM: Write a java program to demonstrate window event handling

PROGRAM
import javax.swing.*;

import java.awt.*;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

public class WindowExample extends Frame implements WindowListener

WindowExample()

addWindowListener(this);

setSize(400,400);

setLayout(null);

setVisible(true);

}
Page | 42

public static void main(String[] args)

new WindowExample();

public void windowActivated(WindowEvent arg0)

{System.out.println("activated");}

public void windowClosed(WindowEvent arg0)

{System.out.println("closed");}

public void windowClosing(WindowEvent arg0)

System.out.println("closing");

System.exit(0);

public void windowDeactivated(WindowEvent arg0)

{System.out.println("deactivated");}

public void windowDeiconified(WindowEvent arg0)

{System.out.println("deiconified");}

public void windowIconified(WindowEvent arg0)

{System.out.println("iconified");}

public void windowOpened(WindowEvent arg0)

{System.out.println("Opened");}

}
Page | 43

OUTPUT
Page | 44

15. ITEM EVENT HANDLING


Date: 15/12/2021

AIM: Write a java program to familiarize item event handling

PROGRAM
import java.awt.event.*;

import java.awt.*;

class item extends WindowAdapter implements ActionListener,ItemListener

Frame f1;
Page | 45

Panel p1;

List l1;

Choice c1;

TextField t1;

Button b1;

Label l2,l3,l4;

item()

f1=new Frame();

p1=new Panel();

l1=new List();

b1=new Button("Add");

t1=new TextField(10);

c1=new Choice();

l2=new Label("Add fruit names please");

l3=new Label("Now select your favourites");

l4=new Label("So you like these");

c1.add(" ");

p1.add(l2);

p1.add(t1);

p1.add(b1);

p1.add(l3);

p1.add(c1);

p1.add(l4);

p1.add(l1);

f1.add(p1);

f1.setSize(500,500);

f1.setVisible(true);

b1.addActionListener(this);

c1.addItemListener(this);

f1.addWindowListener(this);
Page | 46

public void WindowClosing(WindowEvent y)

{ System.exit(0);}

public void actionPerformed(ActionEvent e)

c1.add(t1.getText());

t1.setText("");

public void itemStateChanged(ItemEvent e1)

l1.add(c1.getSelectedItem());

public static void main (String args[])

item i1=new item();

OUTPUT
Page | 47

16. USE OF APPLETS


Date: 17/12/2021
Page | 48

AIM: Write a java program to familiarize use of applets by drawing different shapes

PROGRAM
<html>

<body>

<applet code="paraapplet.class" height=500 width=500>

<param name="nam" value="test">

</applet>

</body>

</html>

Sixteen.html

<html>

<body>

<applet code="sixteen.class"height=200 width=200>

</applet>

</body>

</html>

OUTPUT
Page | 49

17. PARAMETERIZED APPLETES


Page | 50

Date:03/ 01/2022

AIM: Write a java program to familiarize the use of parameterized applets

PROGRAM
import java.applet.*;

import java.awt.*;

public class paraapplet extends Applet

public void paint(Graphics g)

//Font font=new Font("Arial",Font.BOLD,26);

//g.setFont(font);

g.setColor(Color.RED);

g.drawString(getParameter("nam"),300,300);

Paraapplet.html

<html>

<body>

<applet code="paraapplet.class" height=500 width=500>

<param name="nam" value="test">

</applet>

</body>

</html>

OUTPUT
Page | 51

18. JDBC
Page | 52

Date :05/0 1/2022

AIM : Write a program to familiarize with JDBC.

PROGRAM
package client;

import java.awt.event.*;

import javax.swing.*;

import java.sql.*;

public class login extends JFrame

Connection con;

Statement st;

ResultSet rs;

JFrame f=new JFrame("User Login");

JLabel l=new JLabel ("Username") ;

JLabel l1=new JLabel("Password");

JTextField t=new JTextField(10);

JTextField t1=new JTextField(10);

JButton b=new JButton("Login");

public login()

connect();

frame();

public void connect()

try

String driver="sun.jdbc.odbc.JdbcOdbcDriver";

Class.forName(driver);
Page | 53

String db="jdbc:odbc:dbl";

con=DriverManager.getConnection(db);

st=con.createStatement();

catch(Exception e)

{}

public void frame()

f.setSize(600, 400);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setVisible(true);

JPanel p=new JPanel();

p.add(l);

p.add(t);

p.add(l1);

p.add(t1);

p.add(b);

f.add(p);

b.addActionListener(new ActionListener()

{public void actionPerformed(ActionEvent e)

try

String username=t.getText().trim();

String password=t1.getText().trim();

String sql=”select Username,Password from Login where Username=” +Username +

“and Password=”+password+””;

rs =st.executeQuery(sql);

System.out.println(sql);

while(rs.next())
Page | 54

System.out.println("Hai");

String user1=rs.getString("Username");

String pass1=rs.getString("Password");

if((username.equals(user1))&&password.equals(pass1))

JOptionPane.showMessageDialog(null,"User found");

else

JOptionPane.showMessageDialog(null,"User not found");

catch(Exception e1)

{}

});

public static void main(String[] args)

login l1 = new login();

}
Page | 55

OUTPUT

You might also like