0% found this document useful (0 votes)
15 views60 pages

Object Oriented Programming Lan Manual

The document is a laboratory manual for the Object-Oriented Programming Lab (LC-CSE-256G) for B.Tech Semester IV students in the Department of CSE (AI&ML). It outlines the vision and mission of the institute and department, program educational objectives, outcomes, specific outcomes, course syllabus, and a list of experiments along with their corresponding course outcomes. Additionally, it includes guidelines for lab conduct, safety precautions, and report preparation.

Uploaded by

karthikeyant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views60 pages

Object Oriented Programming Lan Manual

The document is a laboratory manual for the Object-Oriented Programming Lab (LC-CSE-256G) for B.Tech Semester IV students in the Department of CSE (AI&ML). It outlines the vision and mission of the institute and department, program educational objectives, outcomes, specific outcomes, course syllabus, and a list of experiments along with their corresponding course outcomes. Additionally, it includes guidelines for lab conduct, safety precautions, and report preparation.

Uploaded by

karthikeyant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

OBJECT ORIENTED PROGRAMMING LAB (LC-CSE-256G)

LABORATORY MANUAL
[Link]. Semester- IV

OBJECT ORIENTED PROGRAMMING LAB


Subject code: LC-CSE-256G

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

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Vision and Mission of the Institute

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.

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Vision and Mission of the Department

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.

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Programme Educational Objectives (PEOs)

PEO1- ANALYTICAL SKILLS:


Using a solid foundation in mathematical, scientific, engineering, and current
computing principles, formulate, analyse, and resolve engineering issues in real-world
domain.
PEO2- TECHNICAL SKILLS:
Apply artificial intelligence theory and concepts to analyse the requirements, realise
technical specifications, and design engineering solutions.
PEO3- SOFT SKILLS:
Through inter-disciplinary projects and a variety of professional activities, demonstrate
technical proficiency, AI competency, and foster collaborative learning and a sense of
teamwork.
PEO4- PROFESSIONAL ETHICS:
Excel as socially responsible engineers or entrepreneurs with high moral and ethical
standards, competence, and soft skills that will enable them to contribute to societal
demands and achieve sustainable advancement in emerging computer technologies.

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

PROGRAM OUTCOMES (POs)


PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex
engineering problems.
PO2: Problem analysis: Identify, formulate, review research literature, and analyze
complex engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences, and engineering sciences.
PO3: Design/development of solutions: Design solutions for complex engineering
problems and design system components or processes that meet the specified needs
with appropriate consideration for the public health and safety, and the cultural,
societal, and environmental considerations.
PO4: Conduct investigations of complex problems: Use research-based knowledge and
research methods including design of experiments, analysis and interpretation of data,
and synthesis of the information to provide valid conclusions.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
PO7: Environment and sustainability: Understand the impact of the professional
engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
PO9: Individual and teamwork: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
PO10: Communication: Communicate effectively on complex engineering activities with
the engineering community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.
P11: Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one‟s own work, as a
member and leader in a team, to manage projects and in multidisciplinary
environments.
P12: Life-long learning: Recognize the need for and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change.

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

PROGRAM SPECIFIC OUTCOMES (PSOs)

PSO1: Fundamentals and critical knowledge of the Computer System:


Apply the knowledge gained pertaining to build, asses, and analyze the software
and hardware aspects of the program to solve real world business problems.
PSO2: Comprehensive and applicative knowledge of Software Development:
Ability to evaluate and apply knowledge of data engineering, methodologies, and
able to plan, develop, test, analyze, and manage required aspects in heterogenous
platforms individually or in team work.
PSO3: Applications in Computing Domain:
Ability to acquire computational knowledge and project development abilities
using novel tools and methodologies to tackle challenges in the fields related to
Deep Learning, Machine learning, Artificial Intelligence.
PSO4: Applications in Innovations and Research:
Capacity to direct a team or firm that develops products and to use the
knowledge learned to recognise actual research issues

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

University Syllabus

Course code LC-CSE-256G


Category Engineering Science courses
Course title OBJECT ORIENTED PROGRAMMING LAB

Scheme and Credits L T P Credits


Semester = 4
0 0 4 2
Classwork 25 Marks
Exam 25 Marks
Total 50 Marks
Duration of Exam 03 Hours

1. Program to define a structure of a basic JAVA program


2. Program to define the data types, variable, operators, arrays and control structures.
3. Program to define class and constructors. Demonstrate constructors.
4. Program to define class, methods and objects. Demonstrate method overloading.
5. Program to define inheritance and show method overriding.
6. Program to demonstrate Packages.
7. Program to demonstrate Exception Handling.
8. Program to demonstrate Multithreading.
9. Program to demonstrate I/O operations.
10. Program to demonstrate Network Programming.
11. Program to demonstrate Applet structure and event handling.
12. Program to demonstrate Layout managers.

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Course Outcomes (COs)


Upon successful completion of the course, the students will be able to:

CO1: Understand the basics of object-oriented programming using JAVA.


CO2: Apply the concept of classes, Java, JDK Components and develop Simple Java
Programs.
CO3: Develop Simple Java Programs using inheritance and Exception handling.
CO4: Develop Multi-threading Programming and Interfaces.
CO5: Develop GUI applications using Applet classes, Swing components and Event handling
programs.

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

CO PSO1 PSO2 PSO3 PSO4


CO1 1 2 1
CO2 1 2 1
CO3 2 2 2
CO4 2 2 2 2
CO5 3 3 3 3

*3-HIGH
*2-MEDIUM
*1-LOW

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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.

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

List of Experiments mapped with COs


S No Program Name CO1, CO2

1. WAP to demonstrate data types available in CO1, CO2


java
2. WAP to design a simple calculator using CO1, CO2
switch case statement
3. WAP to print all prime numbers between 1 to CO1, CO2
1000
4. WAP to implement linear search in 1D array CO1, CO2
5. WAP to implement bubble sort in 1 D array CO1, CO2
6. WAP to multiply 2 matrices in java CO1, CO2
7. WAP to implement recursion function in java CO1, CO2
8. WAP to demonstrate some in-built functions CO1, CO2
on Strings
9. WAP to demonstrate concept of Class, CO1, CO2
Object, and methods in java.
10. WAP to demonstrate method overloading in CO1, CO2
java
11. WAP to demonstrate inheritance in java CO1, CO3
12. WAP to demonstrate multiple inheritance CO1, CO3
using interface
13. WAP to demonstrate method over riding in CO1, CO3
java
14. WAP to demonstrate exception handling in CO1, CO3
java
15. WAP to demonstrate multi-threading in java CO1, CO4
16. WAP to read, write, append data in files CO1
17. WAP to demonstrate database connectivity CO4
using JDBC
18. WAP to create a Swing Application with JDBC CO4
19. WAP to design a Menu using Swing in Java CO4

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

DOs and DON’Ts


DOs

1. Login-on with your username and password.


2. Log off the Computer every time when you leave the Lab.
3. Arrange your chair properly when you are leaving the lab.
4. Put your bags in the designated area.
5. Ask permission to print.

DON’Ts

1. Do not share your username and password.


2. Do not remove or disconnect cables or hardware parts.
3. Do not personalize the computer setting.
4. Do not run programs that continue to execute after you log off.
5. Do not download or install any programs, games or music on computer in Lab.
6. Personal Internet use chat room for Instant Messaging (IM) and Sites is strictly
prohibited.
7. No Internet gaming activities allowed.
8. Tea, Coffee, Water & Eatables are not allowed in the Computer Lab.

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

General Safety Precautions

Precautions (In case of Injury or Electric Shock)


1. To break the victim with live electric source, use an insulator such as fire wood or plastic to
break the contact. Do not touch the victim with bare hands to avoid the risk of electrifying
yourself.
2. Unplug the risk of faulty equipment. If main circuit breaker is accessible, turn the circuit off.
3. If the victim is unconscious, start resuscitation immediately, use your hands to press the
chest
in and out to continue breathing function. Use mouth-to-mouth resuscitation if necessary.
4. Immediately call medical emergency and security. Remember! Time is critical; be best.

Precautions (In case of Fire)

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:

Emergency : 201 (Reception)


Security: 231 (Gate No.1)

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Guidelines to students for report preparation


All students are required to maintain a record of the experiments conducted by them.
Guidelines for its preparation are as follows: -

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.

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Lab Assessment Criteria


An estimated 10 lab classes are conducted in a semester for each lab course. These lab classes
are assessed continuously. Each lab experiment is evaluated based on 5 assessment criteria as
shown in following table. Assessed performance in each experiment is used to compute CO
attainment as well as internal marks in the lab course.
Grading Exemplary (4) Competent (3) Needs Poor (1)
Criteria Improvement
(2)
AC1: Complete Underlined concept Not able to write Underlined concept
Pre-Lab written procedure with is written but concept and is not clearly
work (this may underlined concept procedure is procedure understood
is properly written incomplete
be assessed
through viva)
AC2: Unable to Assigned problem Assigned problem Assigned problem
Program Writing/ understand the is properly is properly is properly
Modeling reason for errors/ analyzed, correct analyzed & correct analyzed
bugs even after they solution designed, solution designed
are explicitly appropriate
pointed out language
constructs/ tools are
applied

AC3: Able to identify Able to identify Is dependent totally Unable to


Identification & errors/ bugs and errors/ bugs and on someone for understand the
Removal of remove them remove them with identification of reason for errors/
errors/ bugs little bit of guidance errors/ bugs and bugs even after they
their removal are explicitly
pointed out

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

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

LAB EXPERIMENTS

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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);
}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

a=10
b=25.63
c=A
d=12.697999954223633
f=true

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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:

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

c=a*b;
[Link]("Multiplication is "+c);
break;
case 4:
c=a/b;
[Link]("Division is "+c);
break;
default:
[Link]("Bad Choice");
break;
}
}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Program No. 3
WAP to print all prime numbers between 1 to 1000
package oopsfile;
import [Link];

public class Program3


{
public static void main(String ar[])
{
int num=2;
//Scanner sc=new Scanner([Link]);
//[Link]("Enter any number");
//num=[Link]();
for(num=2;num<100;num++)
{
int i=2;
while(i<num)
{
if(num%i==0)
{
//[Link]("NUmber is not Prime");
if(num==2)
[Link](num);
break;
}
i++;
if(i==num)
[Link](num);
}
}}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Program No. 4
WAP to implement linear search in 1D array
package oopsfile;

import [Link];

public class Program4 {

public static void main(String[] args) {


// TODO Auto-generated method stub
int a[]= {10,20,30,50,5,15,25,35,45,55,76,102,7};
int item=0;
int loc=-1;
[Link]("Enter the element to be search");
Scanner sc=new Scanner([Link]);
item=[Link]();
for(int i=0;i<[Link];i++)
{
if(item==a[i])
{
loc=i;
break;
}
}
if(loc==-1)
[Link]("Item not Found");
else
[Link]("Item found at location ="+loc);
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Program No. 5
WAP to implement bubble sort in 1 D array
package oopsfile;

public class Program5 {

public static void main(String[] args) {


// TODO Auto-generated method stub
int a[]= {22,55,99,88,44,33,66,77,11,155,122};
int l=[Link];
for (int i = 0; i < l - 1; i++)
for (int j = 0; j < l - i - 1; j++)
if (a[j] > a[j + 1])
{
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
for(int i=0;i<l;i++)
[Link](a[i]);
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Program No. 6
WAP to multiply 2 matrices in java
package oopsfile;

import [Link];

public class Program6 {

public static void main(String[] args) {


// TODO Auto-generated method stub
int a[][]=new int[3][3];
int b[][]=new int[3][3];
int c[][]=new int[3][3];
// Data for Matrix A
[Link]("Enter the matrix A");
Scanner sc=new Scanner([Link]);
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
a[i][j]=[Link]();
}
}
// Data for Matrix A
[Link]("Enter the matrix A");
//Scanner sc=new Scanner([Link]);
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
b[i][j]=[Link]();
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
c[i][j]=0;
for(int k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}

}
}
for(int i=0;i<3;i++)
{

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

for(int j=0;j<3;j++)
{
[Link](c[i][j]+"\t");
}
[Link]();
}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Enter the matrix A

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

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Program No. 7
WAP to implement recursion function in java
package oopsfile;

import [Link];

public class Program7 {

public static void main(String[] args) {


// TODO Auto-generated method stub
int num;
Scanner sc=new Scanner([Link]);
num=[Link]();
int factorial;
factorial=fact(num);
[Link](factorial);

}
static int fact(int num)
{
if(num==1)
return 1;
else
return num*fact(num-1);
}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Program No. 8
WAP to demonstrate some in-built functions on Strings
package oopsfile;

public class Program8


{
public static void main(String arg[])
{
String str=new String("Welcome to AIML Department");
//length of string
[Link]("Length of String= "+[Link]());
StringBuilder sb=new StringBuilder(str);

String str2=new String([Link]());


[Link](str2);
str2=new String([Link]());
[Link]([Link]());

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");
}
}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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]());
}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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;
}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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]());

}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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));
}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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]();
}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Program No. 14
WAP to demonstrate exception handling in java
package oopsfile;

class MyException extends Exception


{
public MyException(String message) {
// TODO Auto-generated constructor stub
super(message);
}
}
class Program14
{
public static void main(String args[])
{
int a=5;
int y=1000;
try {
float z=(a)/(y);
if(z<0.01)
{
throw new MyException("Number is too small");
}
}
catch(MyException e)
{
[Link]("Caught my Exception");
}
}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Program No. 15
WAP to demonstrate multi-threading in java
package oopsfile;

class A extends Thread


{
public void run()
{
for(int i=1;i<=5;i++)
{
[Link]("From Thread A="+i);
}
[Link]("Exit from A");
}
}
class B extends Thread
{
public void run()
{
for(int j=1;j<=5;j++)
{
[Link]("From Thread B="+j);
}
[Link]("Exit from B");
}
}
class C extends Thread
{
public void run()
{
for(int k=1;k<=5;k++)
{
[Link]("From Thread C="+k);
}
[Link]("Exit from C");
}
}

class Program15 {

public static void main(String[] args) {


// TODO Auto-generated method stub
new A().start();
new B().start();
new C().start();
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

}
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

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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
{

File old=new File("G:\\DRONACHARYA COLLEGE\\C Codes\\Java


Code\\[Link]");
File neww=new File("G:\\DRONACHARYA COLLEGE\\C Codes\\Java
Code\\[Link]");
FileInputStream fis =new FileInputStream(old);
FileOutputStream fos=new FileOutputStream(neww);
int i;
while((i=[Link]())!=-1)
{
[Link](i);
}
[Link]();
[Link]();
[Link]("Data has been copied Successfully");
}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Program No. 17
WAP to demonstrate database connectivity using JDBC
package oopsfile;
import [Link].*;
public class Program17 {

public static void main(String[] args) {


// TODO Auto-generated method stub

try
{
[Link]("[Link]");

Connection
con=[Link]("jdbc:mysql://localhost:3306/dbtest","root","Manoj@8043
");
Statement stat=[Link]();

ResultSet rs=[Link]("select * from student");

while([Link]())
{
[Link]([Link](1)+"\t");
[Link]([Link](2)+"\t");
[Link]([Link](3)+"\t");
[Link]();
}

}
catch(ClassNotFoundException e)
{

}
catch(SQLException e)
{

}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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);
}
}

class MyFram extends JFrame implements ActionListener


{
JLabel nameLabel,branchLabel,rollLabel;
JTextField nameField,branchField,rollField;
JButton submit;
MyFram()
{
nameLabel=new JLabel("NAME");
branchLabel=new JLabel("BRANCH");
rollLabel=new JLabel("ROLL NO");

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);

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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");
}
}
}
}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

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);

}}

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Output

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

Viva Voce Questions with Answers

1. What is object-oriented programming (OOP)?


OOP is a programming paradigm that treats data as objects. Objects have state and behavior, and they
can interact with each other.

2. What are the four pillars of OOP?


The four pillars of OOP are abstraction, encapsulation, inheritance, and polymorphism.

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.

10. What is a constructor?


A constructor is a special method that is used to initialize an object.

11. What is a static method?


A static method is a method that is associated with a class, not with an object. It can be called without
creating an instance of the class.

12. What is a final method?


A final method cannot be overridden by a subclass.

13. What is a final class?


A final class cannot be inherited from.

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

14. What is a public method?


A public method can be accessed from anywhere in the program.

15. What is a private method?


A private method can only be accessed from within the class that it is defined in.

16. What is a protected method?


A protected method can be accessed from within the class that it is defined in, and from subclasses of
that class.

17. What is an abstract method?


An abstract method is a method that has no implementation. It must be overridden by subclasses.

18. What is an interface?


An interface is a collection of abstract methods. It cannot be instantiated, but it can be used to define
the behavior of a class.

19. What is a package?


A package is a collection of classes and interfaces. It is used to organize code and to control access to
classes and interfaces.

20. What are the advantages of object-oriented programming?


The advantages of object-oriented programming include:
a) Reusability of code
b) Increased modularity
c) Improved code readability and maintainability
d) Increased flexibility and extensibility

21. What is JDBC?


JDBC stands for Java Database Connectivity. It is a Java API that allows Java programs to connect to a
database and perform SQL operations. JDBC is a standard API, so it can be used to connect to any
database that supports JDBC.

22. What are the different types of JDBC drivers?


There are four types of JDBC drivers:
JDBC-ODBC bridge driver: This driver uses the ODBC driver to connect to the database. It is the
simplest type of JDBC driver, but it is also the least efficient.
Native-API driver: This driver uses the client-side libraries of the database. It is more efficient than the
JDBC-ODBC bridge driver, but it requires the native libraries to be installed on each client machine.
Network Protocol driver: This driver uses middleware (application server) that converts JDBC calls
directly or indirectly into the vendor-specific database protocol. It is the most efficient type of JDBC
driver, but it requires an application server to be installed.
Thin driver: This driver converts JDBC calls directly into the vendor-specific database protocol. It is
entirely written in Java, so it is platform-independent.

23. What are the steps involved in using JDBC?


The basic steps involved in using JDBC are:
a) Import the JDBC packages.
b) Register the JDBC driver.

Department of CSE(AI&ML) 2022-23


OOPS Lab (LC-CSE-256G)

c) Create a connection to the database.


d) Create a statement.
e) Execute the statement.
f) Process the results.
g) Close the connection.

24. What are the different types of JDBC statements?


a) There are three types of JDBC statements:
b) Statement: This is the simplest type of JDBC statement. It can be used to execute any SQL
statement.
c) PreparedStatement: This type of statement is pre-compiled, which makes it more efficient
than a regular statement.
d) CallableStatement: This type of statement is used to execute stored procedures.

25. What are the benefits of using JDBC?


a) There are many benefits to using JDBC, including:
b) Platform independence: JDBC is a standard API, so it can be used to connect to any database
that supports JDBC.
c) Performance: JDBC is a well-optimized API, so it can be used to perform database operations
efficiently.
d) Ease of use: JDBC is a relatively easy API to use, even for beginners.

Department of CSE(AI&ML) 2022-23

You might also like