7-Day OOP Learning Journey
Master Object-Oriented Programming in Java - from fundamentals to advanced concepts with hands-on projects
Overview
This comprehensive 7-day structured learning plan (2 hours/day) covers Object-Oriented Programming fundamentals in Java. Each day builds upon previous concepts, progressing from basic programming to advanced OOP principles, culminating in a complete Library Management System project.
Learning Outcomes: Master the four OOP pillars (Encapsulation, Abstraction, Inheritance, Polymorphism) and apply them in real-world scenarios.
01
Programming Fundamentals
Key Concepts Learned
- Variables, operators, loops, and conditionals
- Function creation and simple problem-solving
- Basic algorithms: factorial, prime checking, Fibonacci
Day1Basics.java
// Day1Basics.java
public class Day1Basics {
static int factorial(int n) {
int result = 1;
for (int i = 2; i <= n; i++) result *= i;
return result;
}
static boolean isPrime(int n) {
if (n <= 1) return false;
for (int i = 2; i * i <= n; i++) if (n % i == 0) return false;
return true;
}
public static void main(String[] args) {
int a = 10, b = 3;
System.out.println("a + b = " + (a + b));
System.out.println("Factorial of 5 = " + factorial(5));
System.out.println("Is 13 prime? " + isPrime(13));
}
}
02
Functions & Recursion
Key Concepts Learned
- Modular programming with functions
- Recursive algorithm implementation
- Base case and recursive case design
Day2Functions.java
// Day2Functions.java
public class Day2Functions {
static int factorialRec(int n) {
if (n <= 1) return 1;
return n * factorialRec(n - 1);
}
static int fibRec(int n) {
if (n <= 1) return n;
return fibRec(n - 1) + fibRec(n - 2);
}
public static void main(String[] args) {
System.out.println("Factorial(5) = " + factorialRec(5));
System.out.println("Fibonacci(6) = " + fibRec(6));
}
}
03
Classes & Objects
Key Concepts Learned
- Class definition and object instantiation
- Constructors and method implementation
- Instance variables and method behavior
Car.java & Day3CarDemo.java
// Car.java
class Car {
String brand, model;
int year, mileage;
Car(String brand, String model, int year, int mileage) {
this.brand = brand;
this.model = model;
this.year = year;
this.mileage = mileage;
}
void drive(int km) {
mileage += km;
System.out.println("Driven " + km + " km. Mileage: " + mileage);
}
void display() {
System.out.println(brand + " " + model + " (" + year + ") - " + mileage + " km");
}
}
public class Day3CarDemo {
public static void main(String[] args) {
Car c1 = new Car("Toyota", "Yaris", 2020, 0);
c1.display();
c1.drive(120);
}
}
04
Encapsulation & Abstraction
Key Concepts Learned
- Access modifiers (private, public) for data hiding
- Getter and setter methods for controlled access
- Data validation and business logic encapsulation
BankAccount.java & Day4BankDemo.java
// BankAccount.java
class BankAccount {
private String accountNumber;
private String owner;
private double balance;
BankAccount(String accountNumber, String owner, double balance) {
this.accountNumber = accountNumber;
this.owner = owner;
this.balance = balance;
}
public double getBalance() { return balance; }
public void deposit(double amount) {
if (amount > 0) balance += amount;
}
public void withdraw(double amount) {
if (amount > 0 && amount <= balance) balance -= amount;
else System.out.println("Insufficient funds!");
}
public void display() {
System.out.println("Account: " + accountNumber + ", Owner: " + owner + ", Balance: " + balance);
}
}
public class Day4BankDemo {
public static void main(String[] args) {
BankAccount acct = new BankAccount("AC123", "Anshuman", 500);
acct.display();
acct.deposit(250);
acct.withdraw(200);
acct.display();
}
}
05
Inheritance
Key Concepts Learned
- Code reusability through inheritance
- Parent-child class relationships
- Method overriding with @Override annotation
- Super keyword for parent class access
Person.java & Day5InheritanceDemo.java
// Person.java
class Person {
String name;
int age;
Person(String name, int age) {
this.name = name;
this.age = age;
}
void display() {
System.out.println("Name: " + name + ", Age: " + age);
}
}
class Student extends Person {
String rollNo, course;
Student(String name, int age, String rollNo, String course) {
super(name, age);
this.rollNo = rollNo;
this.course = course;
}
@Override
void display() {
super.display();
System.out.println("Roll No: " + rollNo + ", Course: " + course);
}
}
public class Day5InheritanceDemo {
public static void main(String[] args) {
Student s = new Student("Tanu", 20, "IT40", "B.E. IT");
s.display();
}
}
06
Polymorphism
Key Concepts Learned
- Runtime polymorphism with abstract classes
- Method overriding for dynamic behavior
- Abstract methods and concrete implementations
- Polymorphic method calls and late binding
Shape.java & Day6PolymorphismDemo.java
// Shape.java
abstract class Shape {
abstract double area();
}
class Circle extends Shape {
double radius;
Circle(double radius) { this.radius = radius; }
@Override
double area() { return Math.PI * radius * radius; }
}
class Rectangle extends Shape {
double w, h;
Rectangle(double w, double h) { this.w = w; this.h = h; }
@Override
double area() { return w * h; }
}
public class Day6PolymorphismDemo {
public static void main(String[] args) {
Shape s1 = new Circle(5);
Shape s2 = new Rectangle(4, 6);
System.out.println("Circle area = " + s1.area());
System.out.println("Rectangle area = " + s2.area());
}
}
07
Library Management System
Project Implementation
- Applied Encapsulation, Inheritance, and Polymorphism
- Real-world system design with multiple classes
- Data management and object relationships
- Portfolio-ready project demonstration
Library Management System - Day7LibraryDemo.java
// Book.java
class Book {
String title, author, isbn;
Book(String title, String author, String isbn) {
this.title = title;
this.author = author;
this.isbn = isbn;
}
void display() {
System.out.println("Book: " + title + " by " + author + " [ISBN: " + isbn + "]");
}
}
class Member {
String name;
int memberId;
Member(String name, int memberId) {
this.name = name;
this.memberId = memberId;
}
void display() {
System.out.println("Member: " + name + " (ID: " + memberId + ")");
}
}
class Library {
Book[] books;
int count;
Library(int size) {
books = new Book[size];
count = 0;
}
void addBook(Book b) {
if (count < books.length) {
books[count++] = b;
System.out.println("Book added: " + b.title);
} else {
System.out.println("Library is full!");
}
}
void showBooks() {
System.out.println("--- Library Books ---");
for (int i = 0; i < count; i++) books[i].display();
}
}
public class Day7LibraryDemo {
public static void main(String[] args) {
Library lib = new Library(5);
Book b1 = new Book("OOP in Java", "James Gosling", "111");
Book b2 = new Book("Clean Code", "Robert Martin", "222");
Member m1 = new Member("Anshuman", 101);
lib.addBook(b1);
lib.addBook(b2);
m1.display();
lib.showBooks();
}
}
Key Outcomes Achieved
- OOP Mastery: Complete understanding of Encapsulation, Abstraction, Inheritance, and Polymorphism
- Real-world Application: Learned system design principles for practical Java development
- Portfolio Project: Completed Library Management System demonstrating all OOP concepts
- Programming Foundation: Solid base for advanced Java topics and frameworks