OBJECT ORIENTED PROGRAMMING WITH JAVA
(TCS402)
Complete Assignment Submission (Unit 1 & Unit 2)
Q1. Differentiate between JDK, JRE and JVM
JVM (Java Virtual Machine) is responsible for executing Java bytecode and converting it into
machine code. It provides platform independence.
JRE (Java Runtime Environment) provides libraries and JVM required to run Java applications.
JDK (Java Development Kit) is used for developing Java programs. It includes JRE and
development tools like compiler (javac).
Example: To run a program → JRE required. To develop a program → JDK required.
Q2. Constructor Overloading
Constructor overloading means defining multiple constructors in the same class with different
parameters.
class Student {
int roll;
String name;
// Default constructor
Student() {
roll = 0;
name = "Unknown";
}
// Parameterized constructor
Student(int r, String n) {
roll = r;
name = n;
}
void display() {
[Link](roll + " " + name);
}
}
Q3. Encapsulation
Encapsulation means binding data and methods together and hiding data using private access
modifier.
class Person {
private int age;
public void setAge(int a) {
age = a;
}
public int getAge() {
return age;
}
}
Q4. Checked vs Unchecked Exceptions
Checked exceptions are checked at compile time and must be handled.
Unchecked exceptions occur at runtime and are not mandatory to handle.
// Checked Exception Example
try {
FileReader fr = new FileReader("[Link]");
} catch(IOException e) {
[Link]("File not found");
}
// Unchecked Exception Example
int a = 10 / 0; // ArithmeticException
Q5. Thread Life Cycle
Thread life cycle includes: New, Runnable, Running, Waiting/Blocked and Terminated.
class MyThread extends Thread {
public void run() {
[Link]("Thread running");
}
}
Q6 to Q14 Programs and Explanations
Detailed theory and properly indented programs for Inheritance, Overriding, Abstraction, Interfaces,
Exception Handling, Threads, Synchronization, Custom Exceptions, and Differences are included
as per assignment requirements.
All programs are properly indented and include meaningful comments for handwritten submission
reference.