Affiliated to
Dr. A P J Abdul Kalam Technical University
Lucknow, Uttar Pradesh, 226031
Department of Computer Science and Engineering
SESSION:2025-26(EVEN SEMSTER)
Object Oriented Programming with Java
SUBJECT CODE: BCS452
B. TECH(CSE)
YEAR: SECOND
SEMSESTER: IVth
Student Name: Harish Giri
Roll Number: 2502300109006
Branch/Section: CSE 4th C
Submitted By: Submitted To:
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
INDEX
[Link] Title Date Page Sign
No.
1. Use Java compiler and eclipse platform to write and execute
java program.
2. Creating simple java programs using command line
arguments
3. Understand OOP concepts and basics of Java programming.
4. Create Java programs using inheritance and polymorphism.
5. Implement error-handling techniques using exception handling
and multithreading.
6. Create java program with the use of java packages.
7. Construct java program using Java I/O package.
8.
9.
10.
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
Practical-1
Objective :- To write and execute a simple Java program
using compiler and Eclipse platform.
Tools Used :-
• JDK(Java Development Kit)
• Eclipse IDE
Theory:-
Java is a programming language. We use compiler (javac) to
convert code into bytecode and run using JVM.
Program:-
class Hello {
public static void main(String[] args) {
[Link]("Hello Harish");
}
}
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
Output:-_
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
Practical-2
Objective :- To create a Java program using command line
arguments.
Tools Used :-
• Command Prompt
• JDK
Theory :-
Command line arguments are values passed during program
execution.
Program :-
class Add {
public static void main(String[] args) {
int a = [Link](args[0]);
int b = [Link](args[1]);
int sum = a + b;
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
[Link]("Sum = " + sum);
}
}
Output:-
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
Practical-3
Objective :- Understand OOP concepts and basics of
Java programming.
Tools Used :-
• Eclipse / JDK
Theory :-
OOP is based on class and object.
Program :-
class Student {
int id;
String name;
double marks;
// constructor
Student(int i, String n, double m) {
id = i;
name = n;
marks = m;
}
// method to display data
void displayDetails() {
[Link]("Student ID: " + id);
[Link]("Student Name: " + name);
[Link]("Marks: " + marks);
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
}
// method to check result
void checkResult() {
if (marks >= 40) {
[Link]("Result: Pass");
} else {
[Link]("Result: Fail");
}
}
}
public class OOPSDemo {
public static void main(String[] args) {
Student s1 = new Student(101, "Rahul", 75.5);
Student s2 = new Student(102, "Aman", 35.0);
[Link]("Student 1 Data");
[Link]();
[Link]();
[Link](" ");
[Link]("Student 2 Data");
[Link]();
[Link]();
}
}
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
Output :-
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
Practical-4
Objective :- Create Java programs using inheritance
and polymorphism.
Tools Used :-
• Eclipse / JDK
Theory :-
Inheritance allows one class to use properties of another.
Program :-
class Animal {
void eat() {
[Link]("Animal eats food");
}
void sound() {
[Link]("Animal makes sound");
}
}
class Dog extends Animal {
void sound() {
[Link]("Dog barks");
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
}
void display() {
[Link]("This is Dog class");
}
}
class Cat extends Animal {
void sound() {
[Link]("Cat meows");
}
}
public class InheritancePolymorphismDemo {
public static void main(String[] args) {
Animal a;
a = new Dog();
[Link]();
[Link]();
[Link]();
a = new Cat();
[Link]();
[Link]();
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
}
}
Output:-
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
Practical-5
Objective :- Implement error-handling techniques
using exception handling and multithreading.
Tools Used :-
• Eclipse / JDK
Theory :-
Exception handling is used to avoid program crash.
Program :-
class MyThread extends Thread {
public void run() {
for (int i = 1; i <= 5; i++) {
[Link]("Thread running: " + i);
try {
[Link](500);
} catch (InterruptedException e) {
[Link]("Thread interrupted");
}
}
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
}
}
public class ExceptionHandling {
public static void main(String[] args) {
// Exception Handling
try {
int a = 10;
int b = 0;
int result = a / b;
[Link](result);
} catch (ArithmeticException e) {
[Link]("Cannot divide by zero");
}
[Link]("Program continues...");
// Multithreading
MyThread t1 = new MyThread();
[Link]();
}
}
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
Output:-
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
Practical-6
Objective :- Create java program with the use of java
packages.
Tools Used :-
• Eclipse / JDK
Theory :-
Package is a group of classes.
Program :-
[Link]
package mypack;
public class Test {
public void showMessage() {
[Link]("This is inside package");
}
public int square(int num) {
return num * num;
}
}
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
[Link]
package mypack;
public class MainClass {
public static void main(String[] args) {
Test obj = new Test();
[Link]();
int result = [Link](5);
[Link]("Square = " + result);
}
}
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
Output:-
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
Practical-7
Objective :- Construct java program using Java I/O
package.
Tools Used :-
• Eclipse / JDK
Theory :-
Java I/O is used for input and output operations.
Program :-
import [Link];
public class JavaIO {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter your name: ");
String name = [Link]();
[Link]("Enter marks: ");
int marks = [Link]();
[Link]("\n----- Result -----");
[Link]("Name: " + name);
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006
Department of Computer Science &Technology
Subject: Object Oriented Programming with Java
Subject code: BCS452
[Link]("Marks: " + marks);
if (marks >= 40) {
[Link]("Status: Pass");
} else {
[Link]("Status: Fail");
}
[Link]();
}
}
Output:-
Branch: CSE Year/Section: IInd/C University Roll No: 2502300109006