0% found this document useful (0 votes)
99 views

Lec-1 (Object Oriented Programming)

This document outlines the syllabus for the CS F213 Object Oriented Programming course at BITS Pilani, including an overview of object-oriented programming concepts like classes, objects, encapsulation, inheritance, and polymorphism. It provides the course schedule, evaluation criteria, instructor contact information, and recommended textbooks. Key topics to be covered include the basic features of OOP, Java syntax, and compiling and executing Java programs.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Lec-1 (Object Oriented Programming)

This document outlines the syllabus for the CS F213 Object Oriented Programming course at BITS Pilani, including an overview of object-oriented programming concepts like classes, objects, encapsulation, inheritance, and polymorphism. It provides the course schedule, evaluation criteria, instructor contact information, and recommended textbooks. Key topics to be covered include the basic features of OOP, Java syntax, and compiling and executing Java programs.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

CS F213 Object Oriented

Programming
BITS Pilani Dr. Yashvardhan Sharma
CSIS Dept., BITS-Pilani
Pilani Campus

BITS Pilani, Pilani Campus


Today’s Agenda

• Course Overview
• Object Basics
• Three Pillars of OOP
• Basic Java Syntax
• Compiling/Executing Java Programs

BITS Pilani, Pilani Campus


Contact Info

• Chamber Consultation Hour – Thursday 5:00-


6:00pm
• Chamber – 6111-C (IPC)
• Email: [email protected]
• Course Web site:
https://nalanda.bits-pilani.ac.in

3
4-Jan-20
BITS Pilani, Pilani Campus
Course Information

• CS F213
– 4 Unit Course
• Three Lectures / Week
– T TH S– 12:00 -12:50 PM
• Labs: 2 hours/week
– M TWFS – 2:00- 4:00 PM
– TH - 8:00-10:00 AM
• Text Books:
– T1 - Java: The Complete Reference, Herbert Schildt, McGraw Hill
Education, Tenth Edition, 2017
– T2- Object Oriented Design & Patterns, Cay Horstmann, John Wiley
& Sons, 2004
• Reference Books :
– R1- JavaTM Design Patterns – A Tutorial, James W. Cooper, Addison-Wesley, 2000

4
4-Jan-20
BITS Pilani, Pilani Campus
Evaluation Scheme:

Component Duration Weightage (%) Date & Time Nature of component


(Close Book/ Open
Book)
Mid-Semester Test 90 Min. 30 04/10 (9:00- Closed Book
10:30AM)
Comprehensive 180 Min. 40 11/12 (FN) Partly Open Book
Examination
Online Test 120 Min. 25 10/11/2019 Open Book
Lab Attendance 2h 5 NA Open Book

5
BITS Pilani, Pilani Campus
Introduction to Object Oriented
Programming

 Object-Oriented Programming (OOP) is the term used to describe a


programming approach based on objects and classes.
 Allows us to organize software as a collection of objects that consist of
both data and behavior.
 Conventional Structural programming practice only loosely connects data
and behavior.

BITS Pilani, Pilani Campus


Features of OOP

 An object-oriented programming language generally supports five main


features:
 Classes

 Objects

 Abstraction

 Encapsulation

 Inheritance

 Polymorphism

BITS Pilani, Pilani Campus


What’s Object
• Term Object Means Combination of Data (Attributes) and Logic (Behavior,
Functions, Operations) of some real world entity
• Every object has two parts :
- Data Part [ Instance Fields in Java, Attributes or properties]
- Operations Part [ methods in java, Behavior]
• Examples :
1. Account :
Attributes : Account Holder, Account type [saving , current] ,
Balance
Opeartions : deposit, withdraw,
2. BOX:
Attributes : length, width, height, color
Operations : compute area, compute volume

Methods Methods
Object keeps Data Part +
Operation Part Together Data

Methods Methods
What’s class

• Objects are grouped in classes


• Class collections of objects having similar
behavior and properties
• A single object is simply an instance of class.
• Objects can not be instantiated (or created)
without defining a class
• Classes are defined whereas objects are
created.

BITS Pilani, Pilani Campus


Object State
• Properties/Attribute Values at a particular moment represents the state of an
object
• Object may or may not change state in response to an outside stimuli.
• Objects whose state can not be altered after creation are known as immutable
objects and class as immutable class [ String class in Java]
• Objects whose state can be altered after creation are known as mutable objects
and class as mutable class [ StringBuffer class in Java]

States of Three Different INSTANCES of CAR CLASS

MARUTI800 MarutiESTEEM MARUTIZEN

Name : maruti800 Name : marutiEsteem Name : marutiZen


Price : 200789 Price : 500789 Price : 200789
Color : Red Color : whilte Color : metallic white

BITS Pilani, Pilani Campus


Data Abstraction

• Way of managing complexity


• Abstraction refers to the act of representing
essential features that are of interest of the
users without including background details or
explanation
• Classes use the concept of encapsulation for
hiding unnecessary implementation details

BITS Pilani, Pilani Campus


Pillars of OOP

• Encapsulation
• Inheritance
• Polymorphism

BITS Pilani, Pilani Campus


Encapsulation

• Encapsulation means wrapping up of data and


methods (operations , code) together
• Access to code and data is tightly controlled.
• Through we can define what and what can not be
accessible outside. [ public , private , protected ]

Methods Methods

Encapsulation keeps Data Part +


Operation Part Together inside a Data
capsule
Methods Methods

BITS Pilani, Pilani Campus


Encapsulation Example
class BOX
{ BOX Class
private double length;
private double width; area()

private double height; length


width
height

public double area() { } volume()


public double volume() { }

} // End of class BOX


BITS Pilani, Pilani Campus
Inheritance
• Process by which one object acquires properties of other classes
• Supports Reusability of code and data
• The class whose properties are extended is known as super or base or
parent class.
• The class which extends the properties of super class is known as sub
or derived or child class
• In Java a class can either extends another class or can implement an
interface

A <<class>> A <<interface>>

B <<class>> B <<class>>

class B extends A class B implements A


BITS Pilani, Pilani Campus
Various Forms of Inheritance
Single Inheritance Hierarchical Inheritance

A A X X

B B A B C A B C

NOT SUPPORTED BY JAVA


MultiLevel Inheritance Multiple Inheritance
SUPPORTED BY JAVA
A A A B A B

B B

C C
C C

BITS Pilani, Pilani Campus


Polymorphism

• Poly means many and morph means forms.


• One Interface Many forms
• One Interface for several general class of actions
• In Java we have two types of polymorphisms
1. Compile-Time [ Method Overloading]
2. Run-Time [ Method Overriding]

BITS Pilani, Pilani Campus


Method OverLoading
• Two methods are said to be overloaded if they have same name and
different signatures.
• Signature of method means number of arguments to method and their
types.
• Two methods are said to have different signatures if they differ in
number of arguments they receive or their types
• Example Signature
Signatures
1. int sum (int a, int b) sum(int,int)
2. float sum (int a, float b) sum(int,float)
3. double sum(double a , double b) sum(double,double)
4. void draw(); draw()

Note : return type and name of arguments are not part of


signatures BITS Pilani, Pilani Campus
Method Overloading Examples

1. void sum(int a,int b)


2. int sum(float a, float b)
3. double sum (double a , double b) Overloaded
4. int sum(int a, float b) Methods
5. float sum(float a,int b)

1. void sum(int a,int b) 1,2 and 3,4 Not


2. int sum(int x, int y) Overloaded
3. double sum (double a , double b)
4. float sum(double a1, double b) 1,3 and 2,4 are
overloaded
BITS Pilani, Pilani Campus
Java Features

• Compiled and Interpreted


• Platform Independent
• Architectural Neutral

BITS Pilani, Pilani Campus


Java Program Structure

Documentation Section
1. /**…… */ Documentation Comments
2. // Single Line Comment
3. /*…… */ Multi line Comments
Package Statement

Import Statements

Interface Statements

Class Definitions

Main Method class

BITS Pilani, Pilani Campus


Compiling/Executing a Java
Application

Source Code << .java file>>

Java Compiler << javac .java >>

ByteCode << .class file>>

Java Interpreter << java [name of class] >>

Machine Code

BITS Pilani, Pilani Campus

You might also like