KTU OOP Java2024 Scheme • 60M ESE
MODULE 1/Section 2: Object-Oriented Programming Concepts

Introduction to OOP, Class as an ADT & Procedural vs Object-Oriented Programming

HIGH PRIORITY (Prep Guide)Official Syllabus~15 min study
Official KTU 2024 Syllabus Topics Covered Here
Introduction to OOPProcedural programming versus object-oriented programmingAdvantages of OOP

1. Topic Introduction

Before OOP became the industry standard, large programs written in procedural languages (like C) often turned into fragile tangled webs of global variables and functions. Object-Oriented Programming (OOP) restructures software around interacting real-world objects that protect their own data—making massive systems understandable, modular, and reusable.

2. Start From Zero: An Unorganized Open Warehouse vs Specialized Bank Departments

In Procedural Programming (like C), imagine placing all cash in one open table in the middle of a room (global data) while dozens of workers (functions) reach in and modify it directly. If one worker alters a rule, five other functions break! In Object-Oriented Programming, every department (Account, LibraryMember, Book) locks its own cash inside a safe (private attributes) and provides a service window (public methods) like deposit() or issueBook(). Other objects must politely request service via those windows!

Key Takeaway: Procedural programming decomposes problems into functions acting on passive/global data (top-down); OOP decomposes problems into interacting objects bundling state + behavior (bottom-up).

3. Essential Exam Definitions

Object-Oriented Programming (OOP)
A programming paradigm that models software as a collection of interacting objects, where each object combines internal data (attributes) and allowed operations (methods).
Procedural Programming Paradigm
A top-down paradigm (e.g., C, Pascal) focused on step-by-step procedures/functions operating on separate data structures, often exposing data globally.
Class as an Abstract Data Type (ADT)
A class satisfies both requirements of an ADT: (1) it is a Data Type defining a set of values and operations that can be instantiated into objects, and (2) its internal data representation is Abstracted (hidden) behind methods.

4. Detailed Technical Explanation & Syntax

1. Problem Decomposition Using Objects (Library System Example)

In a Library Automation System, rather than writing isolated issue_book() and return_book() C functions reading global arrays, OOP identifies tangible real-world entities (LibraryMember, Book, IssueRegister) and conceptual entities (Scheduler, NotificationService).

For example, a LibraryMember object bundles private attributes (memberId, name, address, booksIssued) with public operations (issueBook(), returnBook(), findBooksOverdue()). Breaking a huge problem into cohesive objects makes design and maintenance intuitive.

2. Why Every Class is an ADT (Abstract Data Type)

In your lecture notes, an important conceptual question is: 'Is a class an ADT?' Let us prove it cleanly in two steps:

  • Abstract Data: Data contained inside an object is accessible ONLY through its methods; callers have zero knowledge of whether internal storage uses an array, stack, or linked list.
  • Data Type: A data type defines values + operations and can be instantiated (int i; instantiates int). Because a class can be instantiated into objects (LibraryMember m1 = new LibraryMember();), a class IS a data type.
  • Conclusion: Every Class is an ADT! (However, the converse is not always true—an ADT in non-OOP languages like C struct + functions is an ADT without being a class).

5. Working Principle: How Objects Collaborate Without Corrupting Each Other

  1. Object A needs information from Object B (e.g., IssueRegister needs to know if LibraryMember can borrow another book).
  2. Object A does NOT directly read or edit Object B's private booksIssued field.
  3. Instead, Object A sends a message (invokes member.canBorrow()) — Object B checks its own rules and responds safely.

6. Examination-Ready Diagrams

Diagram 3

OOP Concepts (Four Pillars)

OOP ParadigmClasses (Templates) & Objects (Instances)1. EncapsulationBind data + methods; private hiding2. AbstractionExpose essential; hide details3. InheritanceSubclass reuses Superclass (IS-A)4. PolymorphismOne interface, many forms

Visual overview of the four core pillars of Object-Oriented Programming surrounding Class & Object decomposition.

Key Components
  • Abstraction: Shows essential features while hiding internal implementation complexity.
  • Encapsulation: Binds data + methods together inside a class and protects data via private access.
  • Inheritance: Allows a subclass to acquire properties and behaviors of a superclass (extends).
  • Polymorphism: One interface, multiple forms — compile-time overloading and runtime overriding.
Step-by-Step Flow
  1. Encapsulation wraps private fields and public methods into a safe unit (class).
  2. Abstraction exposes only relevant contracts (abstract classes / interfaces).
  3. Inheritance builds specialized subclasses reusing common parent attributes.
  4. Polymorphism lets the same method call behave differently depending on arguments or runtime object.
How to Draw in KTU Exam
  • Draw a central hub labeled 'Object-Oriented Programming (Class & Object)' connected to 4 pillars: Encapsulation, Abstraction, Inheritance, Polymorphism.
  • Inside each pillar box, add a 3–4 word exam keyword: e.g., 'Data + Methods, private', 'Hide complexity', 'IS-A reuse (extends)', 'Many forms (Overload/Override)'.

7. Complete Java Code Examples & Tracing

OOP Modeling & Class as an ADT (LibraryMember Example)LibrarySystemDemo.java
Illustrates decomposing a library workflow into interacting objects where private state is protected behind public methods.
1class LibraryMember {
2 // Abstracted internal data (hidden from external objects)
3 private int memberId;
4 private String name;
5 private int booksIssued;
6 private static final int MAX_BOOKS = 3;
7
8 public LibraryMember(int memberId, String name) {
9 this.memberId = memberId;
10 this.name = name;
11 this.booksIssued = 0;
12 }
13
14 // Well-defined public operations (ADT interface)
15 public boolean issueBook(String bookTitle) {
16 if (booksIssued < MAX_BOOKS) {
17 booksIssued++;
18 System.out.println(name + " (#" + memberId + ") borrowed: " + bookTitle);
19 return true;
20 }
21 System.out.println("Limit reached for " + name + "! Cannot issue: " + bookTitle);
22 return false;
23 }
24
25 public void returnBook(String bookTitle) {
26 if (booksIssued > 0) {
27 booksIssued--;
28 System.out.println(name + " returned: " + bookTitle);
29 }
30 }
31
32 public int getBooksOutstanding() {
33 return booksIssued;
34 }
35}
36
37public class LibrarySystemDemo {
38 public static void main(String[] args) {
39 LibraryMember member = new LibraryMember(104, "Meera");
40 member.issueBook("Java Complete Reference");
41 member.issueBook("Clean Code");
42 member.returnBook("Clean Code");
43 System.out.println("Books currently held: " + member.getBooksOutstanding());
44 }
45}
Expected Output
Meera (#104) borrowed: Java Complete Reference
Meera (#104) borrowed: Clean Code
Meera returned: Clean Code
Books currently held: 1
Keywords:classprivatepublicnew
Common Exam & Coding Mistakes
  • Leaving fields public and letting external code mutate member.booksIssued = 99; directly.
  • Confusing a Class (blueprint) with an Object (runtime instance).

Comparison Tables

Procedural Programming vs Object-Oriented Programming
Comparison PointProcedural Programming (e.g., C)Object-Oriented Programming (e.g., Java)
Core FocusAlgorithms / Functions (procedures)Objects bundling data + methods
ApproachTop-down decompositionBottom-up decomposition
Data SecurityLow; data often shared globally across functionsHigh; private data hidden via encapsulation
Code ReuseLimited (function copy or libraries)High via Inheritance, Polymorphism & Composition
Coupling & MaintenanceTight coupling; changing global data breaks functionsWeak coupling; easy to extend large systems
Real-World MappingHarder to map entities directlyMaps directly to real-world & conceptual entities

Advantages

  • Code and design reuse via class libraries and inheritance.
  • Increased productivity, easier testing, and simplified maintenance.
  • Better management of large problem complexity via intuitive abstraction and weak coupling.

Limitations / Disadvantages

  • Slight runtime overhead (extra indirection, dynamic dispatch, object allocation) making OOP marginally slower than raw procedural C in tight low-level loops.
  • Data centralized in a procedural program becomes distributed across multiple interacting objects, requiring careful architectural design.

Real-World Applications

  • Banking systems, university ERP portals, GUI frameworks (Swing), and enterprise backend platforms.

Important KTU Exam Points

  • Expect a direct 3-mark or 6-mark comparison table between Procedural Programming and OOP.
  • Know the exact proof for 'Is a class an ADT?': Abstract Data (hidden behind methods) + Data Type (instantiable) = ADT.
  • Mention BOTH advantages AND disadvantages of OOD when asked in 6/9-mark theory answers!

Memory Techniques & Revision

  • Proc = 'Top-Down, Functions First, Open Data'; OOP = 'Bottom-Up, Objects First, Hidden Data'.

Common Pitfalls to Avoid

  • Saying OOP is always faster at CPU execution than C — OOP trades tiny runtime overhead for huge gains in safety, maintainability, and scalability.

KTU-Style Questions & Exam-Ready Answers

Structured specifically for KTU Part A (3-mark) and Part B (6/9-mark) evaluation rubrics.

Introduction: Procedural Programming and Object-Oriented Programming represent two fundamental paradigms for structuring software systems.

  • Focus: Procedural programming prioritizes functions/procedures acting on separate data; OOP models self-contained objects binding data and methods together.
  • Design Direction: Procedural uses top-down design; OOP uses bottom-up design.
  • Data Hiding: Procedural exposes data globally (less secure); OOP protects data using access modifiers (private, protected) and encapsulation.
  • Extensibility & Reuse: OOP enables inheritance and polymorphism (one interface, multiple methods), yielding weak coupling and easier maintenance for large applications.

Quick Understanding Check

1. Which statement accurately describes the relationship between Class and ADT?