Lec 1
-
Upload
garapatiavinash -
Category
Documents
-
view
42 -
download
2
description
Transcript of Lec 1
BITS Pilani, Pilani Campus
BITS PilaniPilani Campus
Dr. Yashvardhan SharmaCSIS Dept., BITS-Pilani
IS F213 Object Oriented Programming
BITS Pilani, Pilani Campus
2
Contact Info
• Email: [email protected]• Course Web site: http://csis/faculty/yash/OOP/ISF213.htm
Apr 10, 2023
BITS Pilani, Pilani Campus
3
Course Information
• Three Lectures / Week– M W F – 12:00 -12:50 PM
• Labs: 3 hours/week– T TH – 2:00- 5:00 PM
• Total Lectures: 40(Planned)• Text Books:
– T1: Object Oriented Design & Patterns, Cay Horstmann, John Wiley & Sons, 2nd Edition, 2006
• Reference Books :– 1. The complete Reference Java 2, 5th Edition, Herbert Schildt, Tata
McGraw Hill publishing– 2. JavaTM Design Patterns – A Tutorial, James W. Cooper, Addison-Wesley,
2000Apr 10, 2023
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
5
Evaluation Scheme:
Component Duration Date, Time and Venue
Marks Nature
Midsem Test 50 minutes 50 Closed Book
Tutorials 30 minutes 30 Closed Book
Online Test 90 minutes 40 open book
Comprehensive 3 hours 80 Partly open book
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
Data
Methods Methods
Methods Methods
Object keeps Data Part + Operation Part Together
BITS Pilani, Pilani Campus
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
Name : maruti800Price : 200789Color : Red
MarutiESTEEM
Name : marutiEsteemPrice : 500789Color : whilte
MARUTIZEN
Name : marutiZenPrice : 200789Color : 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 ]
Data
Methods Methods
Methods Methods
Encapsulation keeps Data Part + Operation Part Together inside a capsule
BITS Pilani, Pilani Campus
Encapsulation Example
class BOX
{
private double length;
private double width;
private double height;
public double area() { }
public double volume() { }
} // End of class BOX
lengthwidthheight
area()
volume()
BOX Class
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
B <<class>>
<<interface>>A
B
<<class>>
<<class>>
class B extends A class B implements A
BITS Pilani, Pilani Campus
Various Forms of Inheritance
A
B
Single Inheritance
A
B
Hierarchical Inheritance
X
A B C
X
A B C
MultiLevel Inheritance
A
B
C
A
B
C
A B
C
Multiple InheritanceNOT SUPPORTED BY JAVA
A B
C
SUPPORTED BY JAVA
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
1. int sum (int a, int b)
2. float sum (int a, float b)
3. double sum(double a , double b)
4. void draw();
sum(int,int)
sum(int,float)
sum(double,double)
draw()
Note : return type and name of arguments are not part of signatures
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)
4. int sum(int a, float b)
5. float sum(float a,int b)
Overloaded Methods
1. void sum(int a,int b)
2. int sum(int x, int y)
3. double sum (double a , double b)
4. float sum(double a1, double b)
1,2 and 3,4 Not Overloaded
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 Section1. /**…… */ Documentation Comments2. // Single Line Comment3. /*…… */ 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 Compiler
ByteCode
<< .java file>>
<< javac .java >>
<< .class file>>
Java Interpreter
Machine Code
<< java [name of class] >>