Object Oriented Programming Lan Manual
Object Oriented Programming Lan Manual
LABORATORY MANUAL
[Link]. Semester- IV
DEPARTMENT OF CSE(AI&ML)
OOPS Lab (LC-CSE-256G)
Table of Contents
1. Vision and Mission of the Institute
2. Vision and Mission of the Department
3. Programme Educational Objectives (PEOs)
4. Programme Outcomes (POs)
5. Programme Specific Outcomes (PSOs)
6. University Syllabus
7. Course Outcomes (COs)
8. CO- PO and CO-PSO mapping
9. Course Overview
10. List of Experiments
11. DOs and DON‟Ts
12. General Safety Precautions
13. Guidelines for students for report preparation
14. Lab assessment criteria
15. Lab Experiments
Vision:
“To impart Quality Education, to give an enviable growth to seekers of learning, to groom
them as World Class Engineers and managers competent to match the expending expectations
of the Corporate World has been ever enlarging vision extending to new horizons of
Dronacharya College of Engineering”
Mission:
M1: To prepare students for full and ethical participation in a diverse society and encourage
lifelong learning by following the principle of „Shiksha evam Sahayata‟ i.e., Education &
Help.
M2: To impart high-quality education, knowledge and technology through rigorous academic
programs, cutting-edge research, & Industry collaborations, with a focus on producing
engineers& managers who are socially responsible, globally aware, & equipped to
address complex challenges.
M3: Educate students in the best practices of the field as well as integrate the latest research
into the academics.
M4: Provide quality learning experiences through effective classroom practices, innovative
teaching practices and opportunities for meaningful interactions between students and
faculty.
M5: To devise and implement programmes of education in technology that are relevant to the
changing needs of society, in terms of breadth of diversity and depth of specialization.
Vision:
To cultivate skills and make proficient engineers cum trainers in the domain of Artificial
Intelligence & Machine Learning for exceptional contributions to the society.
Mission:
M1: To impart intense training and learning to generate knowledge through the
state-of-the-art concepts and technologies in Artificial Intelligence and
Machine Learning.
M2: To establish centres of excellence by collaborating with the leading
industries to exhilarate innovative research and development in AIML and
its allied technology.
M3: To inculcate regenerative self-learning abilities, team spirit, and professional
ethics among the students for noble cause.
University Syllabus
CO-PO Mapping
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1 1 1 1 2 2
CO2 1 1 1 2 2
CO3 2 2 2 2 2 2
CO4 2 2 3 3 2 3 2
CO5 3 3 3 3 3 3 3 3 3
CO-PSO Mapping
*3-HIGH
*2-MEDIUM
*1-LOW
Course Overview
Object-Oriented Programming (OOP) is a programming paradigm that treats data and the
functions that operate on that data as a single unit. In Java, objects are the basic building blocks
of all programs.
An object-oriented programming course in Java typically covers the following topics:
Objects and classes: Objects are instances of classes, which are templates for creating objects.
Classes contain data members (variables) and methods (functions) that define the behavior of
objects. Inheritance: Inheritance is the ability of one class to inherit the properties of another
class. This allows for code reuse and makes it easier to create complex programs.
Polymorphism: Polymorphism is the ability of an object to take on different forms. This is
achieved through the use of abstract classes and interfaces.
Encapsulation: Encapsulation is the hiding of data members from other parts of the program.
This helps to protect data and make programs more secure.
Exception handling: Exception handling is a way of dealing with errors that occur during
program execution. This helps to prevent programs from crashing and makes them more
robust.
In addition to these core concepts, an object-oriented programming course in Java may also
cover topics such as:
GUI programming: GUI programming is the development of graphical user interfaces. This is a
key skill for Java developers, as many Java applications use GUIs.
Collections: Collections are data structures that store and organize data. Java provides a
number of different collection classes, which can be used to store and manipulate data in a
variety of ways.
Algorithms: Algorithms are step-by-step procedures for solving problems. Java developers
need to be familiar with a variety of algorithms in order to write efficient and effective
programs.
Object-oriented programming is a powerful programming paradigm that can be used to create
complex and sophisticated programs. A course in object-oriented programming in Java can
provide you with the skills and knowledge you need to become a successful Java developer.
DON’Ts
1. Turn the equipment off. If power switch is not immediately accessible, take plug off.
2. If fire continues, try to curb the fire, if possible, by using the fire extinguisher or by covering
it with a heavy cloth if possible, isolate the burning equipment from the other surrounding
equipment.
3. Sound the fire alarm by activating the nearest alarm switch located in the hallway.
4. Call security and emergency department immediately:
1) All files must contain a title page followed by an index page. The files will not be signed by
the faculty without an entry in the index page.
2) Student‟s Name, roll number and date of conduction of experiment must be written on all
pages.
3) For each experiment, the record must contain the following
(i) Aim/Objective of the experiment
(ii) Pre-experiment work (as given by the faculty)
(iii) Lab assignment questions and their solutions
(iv) Test Cases (if applicable to the course)
(v) Results/ output
Note:
1. Students must bring their lab record along with them whenever they come for the lab.
2. Students must ensure that their lab record is regularly evaluated.
AC4: All variants of input All variants of input Only few variants Solution is not well
Execution & /output are tested, /output are not of input /output are demonstrated and
Demonstration Solution is well tested, However, tested, implemented
demonstrated and solution is well Solution is well concept is not
implemented demonstrated and demonstrated but clearly explained
concept is clearly implemented
implemented
explained concept is clearly
explained concept is not
clearly explained
AC5: All assigned More than 70 % of Less than 70 % of
Lab Record problems are well the assigned the assigned
Assessment recorded with problems are well problems are well
objective, design recorded with recorded with
constructs and objective, design objective, design
solution along with contracts and contracts and
Performance solution along with solution along with
analysis using all Performance Performance
variants of input analysis is done analysis is done
and output with all variants with all variants
of input and of input and
output output
LAB EXPERIMENTS
Program No. 1
WAP to demonstrate data types available in Java
Source Code:
package oopsfile;
public class Program1
{
public static void main(String args[])
{
int a;
char c;
float b;
double d;
boolean f;
a=10;
c='A';
b=25.63f;
d=12.698f;
f=true;
[Link]("a="+a);
[Link]("b="+b);
[Link]("c="+c);
[Link]("d="+d);
[Link]("f="+f);
}
}
Output
a=10
b=25.63
c=A
d=12.697999954223633
f=true
Program No. 2
WAP to design a simple calculator using switch case statement
Source Code:
package oopsfile;
import [Link];
public class Program2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
[Link]("Press 1: Addition");
[Link]("Press 2: Subtraction");
[Link]("Press 3: Multiply");
[Link]("Press 4: Division");
int a,b,c;
int choice;
[Link]("Enter your choice");
Scanner sc=new Scanner([Link]);
choice=[Link]();
[Link]("Enter First Number");
a=[Link]();
[Link]("Enter Second Number");
b=[Link]();
switch (choice)
{
case 1:
c=a+b;
[Link]("Addition is "+c);
break;
case 2:
c=a-b;
[Link]("Subtraction is "+c);
break;
case 3:
c=a*b;
[Link]("Multiplication is "+c);
break;
case 4:
c=a/b;
[Link]("Division is "+c);
break;
default:
[Link]("Bad Choice");
break;
}
}
}
Output
Press 1: Addition
Press 2: Subtraction
Press 3: Multiply
Press 4: Division
Enter your choice
3
Enter First Number
25
Enter Second Number
6
Multiplication is 150
Press 1: Addition
Press 2: Subtraction
Press 3: Multiply
Press 4: Division
Enter your choice
1
Enter First Number
250
Enter Second Number
300
Addition is 550
Program No. 3
WAP to print all prime numbers between 1 to 1000
package oopsfile;
import [Link];
Output
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
Program No. 4
WAP to implement linear search in 1D array
package oopsfile;
import [Link];
Output
Program No. 5
WAP to implement bubble sort in 1 D array
package oopsfile;
Output
Program No. 6
WAP to multiply 2 matrices in java
package oopsfile;
import [Link];
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
[Link](c[i][j]+"\t");
}
[Link]();
}
}
Output
10 21 47
52 5 7
3 9 41
Enter the matrix B
1 2 3
4 7 8
6 0 1
Product of Matrix A and B
376 167 245
114 139 203
285 69 122
Program No. 7
WAP to implement recursion function in java
package oopsfile;
import [Link];
}
static int fact(int num)
{
if(num==1)
return 1;
else
return num*fact(num-1);
}
}
Output
Program No. 8
WAP to demonstrate some in-built functions on Strings
package oopsfile;
if([Link](str2))
{
[Link]("Strings are equal");
}
else
{
[Link]("Strings are not equal");
}
[Link]([Link]());
if([Link](str2))
{
[Link]("Strings are equal");
}
else
{
[Link]("Strings are not equal");
}
}
}
Output
Program No. 9
WAP to demonstrate concept of Class, Object, and methods in java.
package oopsfile;
class Add
{
int a, b;
void getData(int x,int y)
{
a=x;
b=y;
}
int add()
{
return a+b;
}
}
class Program9
{
public static void main(String[] args)
{
Add add=new Add();
[Link](10, 20);
[Link]("Value of a="+add.a);
[Link]("Value of b="+add.b);
[Link]("Addition of and b="+[Link]());
}
}
Output
Program No. 10
WAP to demonstrate method overloading in java
package oopsfile;
class Program10
{
public static void main(String args[])
{
CalArea ca=new CalArea();
int area;
area=[Link](4);// one parameter
[Link]("Area ="+area);
area=[Link](10,5);// two parameter
[Link]("Area ="+area);
area=[Link](4,5,3);// three parameter
[Link]("Area ="+area);
}
}
class CalArea
{
int area(int x)
{
return x*x;
}
int area(int x,int y)
{
return x*y;
}
int area(int x,int y,int z)
{
return x*y*z;
}
}
Output
Program No. 11
WAP to demonstrate inheritance in java
package oopsfile;
class Room
{
int length,breadth;
Room(int x,int y)
{
length=x;
breadth=y;
}
int area()
{
return length*breadth;
}
}
class Bedroom extends Room
{
int height;
Bedroom(int x,int y,int z)
{
super(x,y);
height=z;
}
int volume()
{
return length*breadth*height;
}
}
class Program11
{
public static void main(String args[])
{
Bedroom b=new Bedroom(14,20,10);
[Link]("Area of Room: "+[Link]());
[Link]("Volume of Room: "+[Link]());
}
}
Output
Program No. 12
WAP to demonstrate multiple inheritance using interface
package oopsfile;
interface Area
{
final static float pi=3.014F;
float compute(float x, float y);
}
class Rectangle implements Area
{
public float compute(float x, float y)
{
return x*y;
}
}
class Circle implements Area
{
public float compute(float x, float y)
{
return pi*x*x;
}
}
public class Program12
{
public static void main(String args[])
{
Rectangle r=new Rectangle();
Circle c=new Circle();
[Link]("Area of Rectangle =:"+[Link](5, 6));
[Link]("Area of Circle =:"+[Link](5, 6));
}
}
Output
Program No. 13
WAP to demonstrate method over riding in java
package oopsfile;
class Super
{
int x;
Super(int x)
{
this.x=x;
}
void display()
{
[Link]("Value of x in Super:"+x);
}
}
class Sub extends Super
{
int y;
Sub(int x,int y)
{
super(x);
this.y=y;
}
void display()
{
[Link]("Value of x in Super:"+x);
[Link]("Value of y in SuB:"+y);
}
}
public class Program13
{
public static void main(String args[])
{
Sub s=new Sub(10,20);
[Link]();
}
}
Output
Program No. 14
WAP to demonstrate exception handling in java
package oopsfile;
Output
Program No. 15
WAP to demonstrate multi-threading in java
package oopsfile;
class Program15 {
}
Output
From Thread A=1
From Thread A=2
From Thread A=3
From Thread A=4
From Thread A=5
Exit from A
From Thread B=1
From Thread B=2
From Thread B=3
From Thread B=4
From Thread B=5
Exit from B
From Thread C=1
From Thread C=2
From Thread C=3
From Thread C=4
From Thread C=5
Exit from C
Program No. 16
WAP to read, write, append data in files
package oopsfile;
import [Link].*;
public class Program16
{
public static void main(String args[]) throws Exception
{
Output
Program No. 17
WAP to demonstrate database connectivity using JDBC
package oopsfile;
import [Link].*;
public class Program17 {
try
{
[Link]("[Link]");
Connection
con=[Link]("jdbc:mysql://localhost:3306/dbtest","root","Manoj@8043
");
Statement stat=[Link]();
while([Link]())
{
[Link]([Link](1)+"\t");
[Link]([Link](2)+"\t");
[Link]([Link](3)+"\t");
[Link]();
}
}
catch(ClassNotFoundException e)
{
}
catch(SQLException e)
{
}
}
Output
Program No. 18
WAP to create a Swing Application with JDBC
package oopsfile;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
class Program18
{
public static void main(String[] args)
{
MyFram mf=new MyFram();
[Link](true);
[Link]("Student");
[Link](400, 400);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](200, 200);
}
}
nameField=new JTextField(10);
branchField=new JTextField(10);
rollField=new JTextField(10);
submit=new JButton("SUBMIT");
setLayout(null);
add(nameLabel);
[Link](50, 40, 60, 50);
add(nameField);
[Link](150, 40, 100, 35);
add(rollLabel);
[Link](50, 100, 60, 50);
add(rollField);
[Link](150, 100, 100, 35);
add(branchLabel);
[Link](50, 150, 60, 50);
add(branchField);
[Link](150, 150, 100, 35);
add(submit);
[Link](100, 250, 100, 30);
[Link](this);
}
public void actionPerformed(ActionEvent e)
{
if([Link]()==submit)
{
try
{
[Link]("[Link]");
Connection
con=[Link]("jdbc:mysql://localhost:3306/dbtest","root","Manoj@8043");
PreparedStatement stat=[Link]("insert into student
values(?,?,?)");
String name=[Link]();
String branch=[Link]();
String roll=[Link]();
int rol=[Link](roll);
[Link](1, rol);
[Link](2, name);
[Link](3, branch);
int i= [Link]();
[Link](this,"Data Saved Successfully");
[Link]("");
[Link]("");
[Link]("");
}
catch(ClassNotFoundException ex)
{
[Link](this,"Class Not Found");
}
catch(SQLException ed)
{
[Link](this,"DataBase Error");
}
}
}
}
Output
Program No. 19
WAP to design a Menu using Swing in Java
package oopsfile;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
class Program20 {
public static void main(String[] args)
{
MenuTest2 mt=new MenuTest2();
[Link]("MENU TEST");
[Link](400, 400);
[Link](true);
[Link](JFrame.EXIT_ON_CLOSE);
}
}
class MenuTest2 extends JFrame
{
JPanel panel;
MenuTest2()
{
JMenuBar jmb=new JMenuBar();
JMenu file=new JMenu("File");
JMenuItem open=new JMenuItem("Open");
JMenuItem close=new JMenuItem("Close");
JMenuItem save=new JMenuItem("Save");
JMenuItem ne =new JMenuItem("New");
[Link](open);
[Link](close);
[Link](save);
[Link](ne);
JMenu edit=new JMenu("Edit");
JMenuItem cut=new JMenuItem("Cut");
JMenuItem copy=new JMenuItem("Copy");
JMenuItem paste=new JMenuItem("Paste");
[Link](cut);
[Link](copy);
[Link](paste);
[Link](file);
[Link](edit);
panel=new JPanel();
[Link](jmb);
add(panel);
}}
Output
3. What is abstraction?
Abstraction is the process of hiding the implementation details of an object and only exposing the
essential details to the user.
4. What is encapsulation?
Encapsulation is the bundling of data and methods together into a single unit. This helps to protect the
data from unauthorized access.
5. What is inheritance?
Inheritance is the ability of a class to inherit the properties and methods of another class. This allows
for code reuse and makes it easier to create complex objects.
6. What is polymorphism?
Polymorphism is the ability of an object to take on different forms. This is achieved through the use of
virtual methods.
7. What is a class?
A class is a blueprint for creating objects. It defines the data and methods that objects of that class will
have.
8. What is an object?
An object is an instance of a class. It has its own state and behavior, and it can interact with other
objects.
9. What is a method?
A method is a block of code that is associated with a class or object. It is used to perform a specific
task.