IMS ENGINEERING COLLEGE
LABORATORY FILE
Object Oriented Programming with java
(BCS-452)
[Link] – II YEAR
(EVEN SEM 2025-2026)
Name VINEET KUMAR THAKUR
Roll No. 2401431650064
Section-Batch 2CSD
DEPARTMENT OF INFORMATION TECHNOLOGY
IMS ENGINEERING COLLEGE
(Affiliated to Dr A P J Abdul Kalam Technical University, Lucknow )
Approved by AICTE - Accredited by NAAC – ‘A’ Grade
NH#24, Adhyatmik Nagar, Ghaziabad, UP, India
[Link]
Vision and Mission of the Institute and Department
Vision (Institution)
To make IMSEC an Institution of Excellence for empowering students through technical
education coupled with incorporating values and developing engineering acumen for
innovations and leadership skills for the betterment of society.
Mission (Institution)
M1: To promote academic excellence by continuous learning in core and
emerging Engineering areas using innovative teaching and learning
methodologies.
M2: To inculcate values and ethics among the learners.
M3: To promote industry interactions and produce young entrepreneurs.
M4: To create a conducive learning and research environment for life-long learning
to develop the students as technology leaders and entrepreneurs for addressing
societal needs
*******
Vision (Department)
To be a department of excellence by imparting state-of-the-art technical education and
preparing globally competent professionals to contribute innovatively to the real-time
requirements of industry and society.
Mission (Department)
M1. To provide strong fundamental and technical skills through effective teaching-
learning practices and hands-on experience with the latest tools and technologies.
M2. To encourage students to become industry-ready professionals by
possessing multidisciplinary skills, leadership abilities, and research-oriented
understanding.
M3. To impart entrepreneurship skills, and develop a sense of respect for social values and
professional ethics among the upcoming IT professionals.
i
PROGRAM OUTCOMES
Engineering Graduates will be able to:
1. Engineeringknowledge: Apply the knowledge of mathematics, science,
engineering fundamentals, and an engineering specialization to the solution of complex
engineering problems
2. 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.
3. 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.
4. 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.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modelling to complex
engineering activities with an understanding of the limitations.
6. 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.
7. 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.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
10. 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.
11. 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.
12. 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.
iv
GENERAL LABORATORY INSTRUCTIONS
1. Students are advised to come to the laboratory at least 5 minutes before (to the
starting time), those who come after 5 minutes will not be allowed into the lab.
2. Plan your task properly much before to the commencement, come prepared to
the lab with the synopsis / program / experiment details.
3. Student should enter into the laboratory with:
• Laboratory observation notes with all the details (Problem statement, Aim,
Algorithm,Procedure, Program, Expected Output, etc.,) filled in for the
lab session.
• Laboratory Record updated up to the last session experiments and other
utensils (ifany) needed in the lab.
• Proper Dress code and Identity card.
4. Sign in the laboratory login register, write the TIME-IN, and occupy the
computer system allotted to you by the faculty.
5. Execute your task in the laboratory, and record the results / output in the lab
observation note book, and get certified by the concerned faculty.
6. All the students should be polite and cooperative with the laboratory staff, must
maintain the discipline and decency in the laboratory.
7. Computer labs are established with sophisticated and high end branded
systems, which should be utilized properly.
8. Students / Faculty must keep their mobile phones in SWITCHED OFF mode
during the labsessions. Misuse of the equipment, misbehaviors with the staff and
systems etc., will attract severe punishment.
9. Students must take the permission of the faculty in case of any urgency to go
out; if anybody found loitering outside the lab / class without permission during
working hours will be treated seriously and punished appropriately.
10. Students should LOG OFF/ SHUT DOWN the computer system before he/she
leaves the lab after completing the task (experiment) in all aspects. He/she must
ensure the system / seatis kept properly.
v
DETAILS OF THE EXPERIMENTS CONDUCTED
(TO BE USED BY THE STUDENTS IN THEIR RECORDS)
INDEX
[Link] TITLE OF THE EXPERIMENT DATE OF FACULTY
SUBMISSION SIGNATURE
vi
EXPERIMENT -1
Program 1- Write a java code to print “Hello World”
class Main {
public static void main(String[] args) {
[Link]("Hello World");
}
}
4
Program -2 Write a java code to find the area of triangle
import [Link].*;
public class Area {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter the base of triangle:-");
int base = [Link]();
[Link]("Enter the height of triangle:-");
int height = [Link]();
// Corrected variable name and spacing
int areaOfTriangle = (base * height) / 2;
[Link]("AREA OF TRIANGLE = " + areaOfTriangle);
}
}
Program-3 Write a java code to check if a given number is prime or not
import [Link].*;
public class Prime {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter the number:");
int n = [Link]();
boolean isPrime = true;
if (n <= 1) {
isPrime = false;
} else {
// We check for factors from 2 up to n/2
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0) {
isPrime = false;
break;
}
}
}
if (isPrime) {
[Link](n + " is a Prime number");
} else {
[Link](n + " is Not a prime number");
}
[Link](); // Good practice to close the scanner
}
}
Program-4 Write a java code to print fibnocci series for n number
import [Link].*;
public class Fibonacci {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter the number of terms:-");
int n = [Link]();
int a = 0, b = 1;
[Link]("Fibonacci Sequence up to " + n + " terms:");
for(int i = 1; i <= n; i++) {
[Link](a + " ");
int nextTerm = a + b;
a = b;
b = nextTerm;
}
[Link]();
}
}
Experiment-2
AIM:- Write a program to crate a class student with data ' name, city, age' along with
method print data to display the data, crate two object with s1, s2 to declare and
access the value
import [Link].*;
class Student {
// Data fields
String name;
String city;
int age;
// Method to display data
public void printData() {
[Link]("Name: " + name);
[Link]("City: " + city);
[Link]("Age: " + age);
[Link]("--------------------");
}
}
public class Main {
public static void main(String[] args) {
// Creating the first object s1
Student s1 = new Student();
[Link] = "Rahul";
[Link] = "Mumbai";
[Link] = 20;
// Creating the second object s2
Student s2 = new Student();
[Link] = "Sneha";
[Link] = "Delhi";
[Link] = 22;
// Accessing the method to display values
[Link]("Student 1 Details:");
[Link]();
[Link]("Student 2 Details:");
[Link]();
}
}
Experiment-3
AIM: Write a program in java to create a class Student2 along with
two method getData(), printData() to get the value through argument
and display the data in printData. Create the two objects s1,s2 to
declare and access the values from class [Link]:
public class Student2 {
String name;
int rollNo;
// Method to get data through arguments
void getData(String n, int r) {
name = n;
rollNo = r;
}
// Method to display the data
void printData() {
[Link]("Student Name: " + name);
[Link]("Roll Number: " + rollNo);
}
// The JVM looks for this specific method signature to start the program
public static void main(String[] args) {
Student2 s1 = new Student2();
[Link]("Alice", 101);
Student2 s2 = new Student2();
[Link]("Bob", 102);
[Link]();
[Link]();
}
}
Experiment-4
Program-1 Java program to illustrate the concept of single inheritance
// Parent Class (Superclass)
class Animal {
void eat() {
[Link]("This animal eats food.");
}
}
// Child Class (Subclass) inheriting from Animal
class Dog extends Animal {
void bark() {
[Link]("The dog barks.");
}
}
public class Main {
public static void main(String[] args) {
// Create an object of the Child class
Dog myDog = new Dog();
// Access method from Parent class
[Link]();
// Access method from Child class
[Link]();
}
}
Program-2 Java program to illustrate the concept of Multilevel inheritance.
import [Link].*;
// In online compilers, the class with 'main' should usually be 'public class Main'
public class Main {
public static void main(String[] args) {
// Create an object of the child-most class
Smartphone myS24 = new Smartphone();
[Link]("--- Testing Multilevel Inheritance ---");
[Link](); // Inherited from Grandparent
[Link](); // Inherited from Parent
[Link](); // Defined in Child
}
}
// Grandparent Class
class Device {
void powerOn() {
[Link]("Device is powering on...");
}
}
// Parent Class
class Phone extends Device {
void makeCall() {
[Link]("Making a phone call...");
}
}
// Child Class
class Smartphone extends Phone {
void browseInternet() {
[Link]("Browsing the internet via 5G...");
}
}
Program-3 A Simple Java program to demonstrate method overriding in java
// Parent Class
class Bank {
// This is the method we will override
void displayInterestRate() {
[Link]("The generic bank interest rate is 6%.");
}
}
// Child Class 1
class SBI extends Bank {
@Override
void displayInterestRate() {
[Link]("SBI Bank Interest Rate: 7.5%");
}
}
// Child Class 2
class ICICI extends Bank {
@Override
void displayInterestRate() {
[Link]("ICICI Bank Interest Rate: 8.2%");
}
}
public class Main {
public static void main(String[] args) {
// Create an object of the Parent class
Bank genericBank = new Bank();
// Create objects of the Child classes
SBI sbiBank = new SBI();
ICICI iciciBank = new ICICI();
// Calling the methods
[Link](); // Runs Parent version
[Link](); // Runs SBI version
[Link](); // Runs ICICI version
}
}
Program-4. Super Keyword in Java Use of super with variables
// Parent Class
class Vehicle {
int maxSpeed = 120; // Parent variable
}
// Child Class
class Car extends Vehicle {
int maxSpeed = 180; // Child variable (hides the parent variable)
void display() {
// Accessing the variable of the current (Child) class
[Link]("Child Class Max Speed: " + maxSpeed);
// Accessing the variable of the Parent class using 'super'
[Link]("Parent Class Max Speed: " + [Link]);
}
}
public class Main {
public static void main(String[] args) {
Car myCar = new Car();
[Link]();
}
}
Experiment-5
Aim: Implement error-handling techniques using exception handling and
multithreading.
Procedure: The Exception Handling in Java is one of the powerful mechanisms to handle the
runtime errors so that the normal flow of the application can be maintained.
Exception is an abnormal condition. An exception is an event that disrupts the normal flow of
the program. It is an object which is thrown at runtime.
Exception Handling is a mechanism to handle runtime errors such as ClassNotFoundException,
IOException, SQLException, Remote Exception, etc.
Advantage of Exception Handling
The core advantage of exception handling is to maintain the normal flow of the application. An
exception normally disrupts the normal flow of the application; that is why we need to handle
Source Code:
public class JavaExceptionProgram1
{
public static void main(String args[])
{
try {
int data = 100 / 0;
}
catch (ArithmeticException e)
{
[Link](e);
}
[Link]("Rest of the code...");
}
}
Output:-
Arithmatic divide by zero
rest of the code..
18
Source Code:
public class Exception1 {
public static void main(String[] args) {
try
{
int data = 50 / 0;
} catch (ArithmeticException e) {
[Link]("Can't divide by zero");
}
}
}
Output:
Divvied by arithmetic’s error
Can't divided by zero
MultiThreading :-
class MyThread extends Thread {
public void run() {
for (int i = 1; i <= 5; i++) {
[Link]([Link]().getName() + " - Value: " + i);
try {
[Link](500);
} catch (InterruptedException e) {
[Link](e);
}
}
}
}
public class ThreadExample {
public static void main(String[] args) {
MyThread t1 = new MyThread();
MyThread t2 = new MyThread();
[Link]("Thread 1");
19
[Link]("Thread 2");
[Link]();
[Link]();
}
}
Output:
Thread 1 - Value: 1
Thread 2 - Value: 1
Thread 1 - Value: 2
Thread 2 - Value: 2
Viva Question:
1. Why Java is not a pure object oriented language?
2. List the features of the Java Programming language?
3. What do you get in the Java download file?
4. List the features of the Java Programming language?
5. What is a Class Loader?
20