0% found this document useful (0 votes)
38 views48 pages

Week 1

The document describes an Object-Oriented Programming course. It includes the course code, subject guide, syllabus, course objectives, books and references, assessment pattern, and topics of the first lecture. The syllabus covers Java basics, classes and objects, I/O, arrays and strings, inheritance, packages and interfaces, collections, exceptions handling, multithreading, and GUI programming. The course aims to teach OOP concepts like encapsulation, inheritance, and polymorphism using Java.

Uploaded by

vikas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views48 pages

Week 1

The document describes an Object-Oriented Programming course. It includes the course code, subject guide, syllabus, course objectives, books and references, assessment pattern, and topics of the first lecture. The syllabus covers Java basics, classes and objects, I/O, arrays and strings, inheritance, packages and interfaces, collections, exceptions handling, multithreading, and GUI programming. The course aims to teach OOP concepts like encapsulation, inheritance, and polymorphism using Java.

Uploaded by

vikas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Object-Oriented Programming

Course Code: IT 2103

Subject Guide: Dr. Aprna Tripathi


Syllabus

• Introduction: OOP paradigm, the creation of java, the java buzzwords; C, C++ and Java
comparison;
• Java Basics: Compilation and execution of a java program, access modifiers, garbage collection;
• Class and Objects: Class definition, creating objects, role of this keyword, garbage collection,
finalize() method, method overloading, objects as parameters, argument passing, returning
objects, access control, final, nested and inner classes;
• I/O Basics: Reading console input, writing console output, Files
• Array and Strings: Arrays in java, 1-D, 2-D and dynamic arrays, string basics, string
comparison and manipulation;
• Inheritance: Inheritance and its types, abstract class, inner and outer class, super, final, static
keywords;
• Package and Interface: In-built packages and user define packages, role of interface,
polymorphism via inheritance;
• Collection Framework & Generics: List, set, map, generic classes;
• Exception Handling: Errors and exceptions, types of exceptions, handling exceptions,
• Multithreading: Thread class, runnable, thread life cycle, synchronization, thread priority;
• Event Handling and GUI Programming: Events, action listener, swing package;

2 IT 2103 : Object-Oriented Programming


Course Objectives
The main objective of the course are as follows:
• To teach students about the basics of classes and objects using Java
programming language
• To enable the students to properly use the basic object oriented
pillars such as encapsulation, inheritance and polymorphism.
• To enable the students to understand the basic difference between a
class and an interface.
• To teach students about the implementation aspect of various basic
data structures such as Linked Lists and Arrays using object oriented
techniques
• To teach students how to provide various types of inheritance and
polymorphism using classes and interfaces
• To introduce students about the role of modern programming
constructs such as exceptions in modern programming languages

3 IT 2103 : Object-Oriented Programming


Books and References

TEXT BOOKS
– Herbert Schildt “Java The Complete Reference”, McGraw
Hill, 11th Edition, December 2020, ISBN-10:9390491622,
ISBN-13: 978-9390491629.

REFERENCE BOOKS
– Balagurusamy E“Programming with Java” , McGraw Hill,
6th Edition, March 2019, ISBN-10: 9353162343, ISBN-13:
978-9353162344.
– Horstmann C. S., “Big Java Early Objects”, Wiley India,
5th Edition, January 2015, ISBN-10:9788126554010,
ISBN-13: 978-8126554010

4 IT 2103 : Object-Oriented Programming


Course Outcomes

• Understand the principles of encapsulation and abstraction via


objects and classes.
• Understand the use of various polymorphic forms using
classes and interfaces on real life problems.
• Learn the application of various forms of inheritance in real
life programming problems.
• Understand the use of advanced programming concepts such
as exception handling, multithreading in problem solving
domain.

5 IT 2103 : Object-Oriented Programming


Assessment Pattern

Criteria Description Maximum Marks


Sessional Exam I (Close Book) 20
Internal Assessment Sessional Exam II (Close Book) 20
(Summative)
In class Quizzes and 20
Assignments
End Term Exam End Term Exam (Close Book) 40
(Summative)
Total 100
Attendance A minimum of 75% Attendance is required to be
(Formative) maintained by a student to be qualified for taking up the
End Semester examination. The allowance of 25%
includes all types of leaves including medical leaves.

6 IT 2103 : Object-Oriented Programming


Lecture 1-Topics

• What is an Object ?
• Graphical View of an Object
• Object Examples
• What is a Class ?
• Object vs Class ?
• Class Examples

7 IT 2103 : Object-Oriented Programming


Guess ??
Who are these guys?
Can you call them individually?
What is Object ?

• Object Means Combination of Data (Attributes) and


Logic (Algorithm, Behavior, Functions, Operations)
of some real world entity. For example Student, Box,
Account, Time
• Every real-world object has two characteristics :
o Data-Part/State [Also known as attributes or properties]
o Behavior [Also known as operations / Algorithmic /
Logic Part]
• Software Object is conceptually similar to a every
real-world object.

11 IT 2103 : Object-Oriented Programming


Object: Graphical View

Object Keeps State/Data Part and


Behavior/Logic Part Together

State/Data
Part

Operations/Logic/Algorithmic Part

A Software
Object

12 IT 2103 : Object-Oriented Programming


Object Examples

• Box Object :
o State/Data Part : length, width, height, Color [Attributes/Instance Fields]
o Behavior Part: computing area, computing volume [Operations, Methods]

• Dog Object :
o State/Data Part : name, breed, color [Attributes / Instance Fields]
o Behavior Part : barking, fetching, wagging [Operations, Methods]

• Account Object :
o State/Data Part : account number, account holder name, balance, type
of account [Attributes/ Instance Fields]
o withdrawing an amount, depositing an amount, checking balance of a
account [ Behavior, Operations, Methods]

13 IT 2103 : Object-Oriented Programming


Object Examples
Box as a Real World Box as a Software Object
Object
computing area
length,
width,
height,
color
computing volume

Dog as a Software Object


Dog as a Real World
Object
barking
name,
wagging breed,
color
fetching

14 IT 2103 : Object-Oriented Programming


Guess the Class of these objects
Guess the Class of these objects
What is Class ?

• Objects are grouped in classes


• A class is a collections of objects having similar
behavior and attributes
• An object is simply a single instance of class.
• Objects can not be instantiated (or created) without
defining a class
• Classes are defined whereas objects are created.
• In order to create an object, you have to first define
the class of that object
• Class does not occupy memory

17 IT 2103 : Object-Oriented Programming


Class Syntax

Access modifier class Class name


{
-methods()
-Constructors()
-Fields
-Blocks
-Nested class
}
Method

A set of codes which performs a particular task


Advantages:
Code reusability
Code optimization
Syntax
Access modifier return-type methodName(list of parameters)
{

}
Access modifier- public, private protector
Default is public
Object

• Object is an instance of class


• Object is real world entity
• Object occupy memory
• Object consists of
Identity – name
State/ attribute- which is represented by fields
Behaviour – which is represented by method
How to create an object in Jave

• There are five methods to create object


• New keyword
• New instance method
• Clone() method
• Deserialization method
• Factory method
Using New keyword

Declaration
It is declaring a variable name with an object type
Ex: Animal buzo; where animal is class and buzo is
reference_variable_name
Working: Animal buzo;
Instantiation: this is when memory is allocated for an object.
New keyword is used to create the object
Ex: Buzo=new
Initialization: the new keyword is followed by a call to a
constructor. This call initials the new object.
Ex: Animal buzo= new Animal(); or
Animal buzo; buzo = new animal();
How to call behaviour of class

Object.method()
Ex: buzo.run();
A small program

class animal1 {
void eat(){
System.out.println("Eating");
}

public static void main(String[] args) {


System.out.println("1");
}
}
A small program

public class animal


{
void eat()
{
System.out.println("buzo is eating");
}
public static void main(String[] args)
{
//creating an object using new keyword
animal buzo = new animal();
//invoking method using the object
buzo.eat();
}
}
A small program

public class animal public class animal


{ {
void eat() void eat()
{
System.out.println("buzo is eating");
{
} System.out.println("buzo is eating");
void run() }
{ void run()
System.out.println("buzo is running"); {
} System.out.println("buzo is running");
public static void main(String[] args)
}
{
//creating an object using new keyword public static void main(String[] args)
animal buzo = new animal(); {
animal zuno = new animal(); //creating an object using new keyword
//invoking method using the object animal buzo = new animal();
buzo.eat(); //invoking method using the object
zuno.run(); buzo.eat();
}
}
buzo.run();
}
}
Exercise -1 Find the state and Behaviour

• Find any two states and behaviour of the following:


• Student
• Employee
• Fruit
• Car
• School

27 IT 2103 : Object-Oriented Programming


Class Example : Box Class
class Box
{
private double length;
private double width; Instance Fields
private double height;
public double area()
{
return 2* (length * width + width * height + height * length);
}
public double volume() Methods
{
return length * width * height;
}
}// End of class

28 IT 2103 : Object-Oriented Programming


Class Example : Box Class
class Box
{
private double length;
Box Class Name
private double width;
- length: double
private double height;
public double area()
- width: double Attributes
- Height: double
{
return 2* (length * width + width * height + height * length); +area() : double
} +volume(): double Methods
public double volume()
{
return length * width * height;
}

:Box
}// End of class

Box b1 = new Box(); b1 length width height

:Box
Box b2 = new Box(); b2 length width height

29 IT 2103 : Object-Oriented Programming


Class Example : Point
class Point Point
{
private double x; - x: double
private double y; - y: double
+getX() : double
public double getX()
+getY(): double
{ +setX(value:double):void
return x; +setY(value:double):void
}
public double
{
getY() Point p1 = new Point();
return y; :Point
}

p1
public void setX(double value)
{
x y
x = value;
}
public void setY(double value)
Point p2 = new Point();
:Point
{
y = value;
}
}// End of class
p2 x y

30 IT 2103 : Object-Oriented Programming


Exercise -2

• Identify any two differences between public and private data.


• difference between state and behaviour in object

31 IT 2103 : Object-Oriented Programming


Lecture 2 -Topics

• Abstraction
• Encapsulation

32 IT 2103 : Object-Oriented Programming


Six key Pilers of OOP

1. Object
2. Class
3. Abstraction
4. Encapsulation
5. Inheritance
6. Polymorphism
OOPs Language

SmallTalk
Java
C++
CSharp
Python
See and find
what this image
says
In this diagram, you can see that
the user only knows there is a
book window for borrowing and
returning books,
He doesn't care or doesn't need to
know about how the book is
found and what happens before
and after he requests or return a
book.
In other words, he is abstracted
from all the details involved in
getting the book to the window.
Abstraction
https://en.wikipedia.org/wiki/Abstraction_(software_engineering)
• Way of managing complexity by suppressing the complex details
• Abstraction refers to the act of representing essential features that are
of interest of the users without including background details or
explanation.
• Users of a complex system are presented with a well defined simple
interface for its use
• Classes use the concept of abstraction for hiding unnecessary
implementation/algorithmic details of its methods.
• As user of any ‘class’ what you should be aware about that class ?

37 IT 2103 : Object-Oriented Programming


Abstraction: Simple Examples

• Suppose you have to compute the square root of a ‘double’


type number in a ‘C’ program. As a programmer what You
have to do.
o #include <math.h>
o Use sqrt() function
• What you will do if you have to compare two strings in a ‘C’
program
o #include <string.h>
o Use strcmp() function

38 IT 2103 : Object-Oriented Programming


Encapsulation

39 IT 2103 : Object-Oriented Programming


Encapsulation

40 IT 2103 : Object-Oriented Programming


Encapsulation

41 IT 2103 : Object-Oriented Programming


Encapsulation

42 IT 2103 : Object-Oriented Programming


Encapsulation

43 IT 2103 : Object-Oriented Programming


Encapsulation – Formal Definition

• Data encapsulation refers to the process of binding together


data and functions or methods operating on this data into a
single unit so that it is protected from outside interference and
misuse.
• Also known as “Data hiding”.
• Encapsulation hides data and its members whereas abstraction
expose only the necessary details or interfaces to the outside
world.

44 IT 2103 : Object-Oriented Programming


Encapsulation : Examples

Encapsulation keeps Data Part + Methods Methods

Operation Part of an object Data


together inside a capsule Methods Methods

class BOX
{
private double length;
private double width;
private double height; Class Capsule

public double area() { }


public double volume() { }
} // End of class BOX

45 IT 2103 : Object-Oriented Programming


Implementation Of Encapsulation

Output
num = 100
ch = Z

46 IT 2103 : Object-Oriented Programming


Exercise

• Think any three difference between Abstraction and


Encapsulation

47 IT 2103 : Object-Oriented Programming


Encapsulation

• Encapsulation means wrapping/binding up of data-part


(state) and methods (operations , code) together in the
form of a capsule.
• Access to code (Methods) and data (instance fields) is
tightly controlled.
• Through Encapsulation, developer of a class can decide
what and what can not be accessible outside a class. [
public , private , protected ]
• A class is a perfect example of an Encapsulation

48 IT 2103 : Object-Oriented Programming

You might also like