Course : FUNDAMENTALS OF JAVA PROGRAMMING
Module 1 : JAVA BASICS
Topic : Review of Object Oriented Concepts
Faculty : S. Karthikeyini S
Sri Ramakrishna Institute of Technology,
Coimbatore
Assistant Professor/CSE
SRI RAMAKRISHNA INSTITUTE OF TECHNOLOGY
[Educational Service: SNR Sons Charitable Trust]
[Autonomous Institution, Reaccredited by NAAC with ‘A’ Grade]
[Approved by AICTE New Delhi, Permanently Affiliated to Anna University, Chennai]
Objective
● Programming Paradigms
● OOPS Concepts
● Benefits
SOFTWARE EVOLUTION
Layers of software
technology
Object Oriented Programming
Procedure Programming
Assembly Language
Machine Language
1, 0
A LOOK AT PROCEDURE-ORIENTED
PROGRAMMING
Main Program
Function 1
Function 8
Function 6
Function 4 Function 5
Function 3
Function 2
Function 7
Global Data Global Data
Function 1
Local Data
Function 1
Local Data
Function 1
Local Data
Some characteristics:
• Emphasis is on doing things (algorithms)
• Large programs are devided into smaller programs
known as function/ subrutin
• Most of the function share global data
• Data move openly around the system from function to function
OOP PARADIGM
DATA
FUNCTIONS
OBJECT A
DATA
FUNCTIONS
OBJECT C
DATA
FUNCTIONS
OBJECT B
BASIC CONCEPTS OF OOP
•
· Objects
•
· Classes
•
· Data abstraction
•
· Encapsulation
•
· Inheritance
•
· Polymorphism
•
· Dynamic binding
•
· Message passing
Some of OOP’s striking features:
▪ Emphasis is on data rather than procedure.
▪ Programs are divided into objects.
▪ Data structures are designed such that they
characterize the objects.
▪ Functions are tied together in the data structures.
▪ Data is hidden and can not be accessed by
external functions.
CLASSES
• It is a blueprint from which objects are
created
• A collection of objects of similar type
• Example:
– Object mango, apple, and orange is member of class fruit
OBJECTS
• It is an instance of a
class.
• Have a life cycle.
• They can be created
and destroyed.
• Interacts by sending
message to one
another
• Contains data and
code/ function to
manipulate the data
Representing notations:
Object: STUDENT
DATA:
Name
Date-of-Birth
Marks
….
FUNCTIONS:
Total
Average
Display
….
STUDENT
Name
Date-of-Birth
Marks
Total
Average
Display
DATA ABSTRACTION
• The act of
representing
essential
features
without
including the
background
details or
explanations.
ENCAPSULATION
• Wrapping up of data and functions into a single unit (called class).
• The data is not accessible to the outside world and only functions
which are wrapped in the class can access it.
• Insulation of the data from direct access by the program is called
data hiding
INHERITANCE
• Is the process by
which objects of one
class acquire the
properties of objects
of another class.
• Supports the
concepts of
hierarchical
classification.
• Provides the idea of
reusability.
Bird
Attributes:
Feathers
Lay eggs
Flying Bird
Attributes:
_________
_________
Non Flying Bird
Attributes:
_________
Robin
Attributes:
_________
_________
Swallow
Attributes:
_________
_________
Penguin
Attributes:
_________
_________
Kiwi
Attributes:
_________
_________
• Example: the bird robin is a part of the
class flying bird which is again a part
of the class bird.
POLYMORPHISM
• The ability to take more than one form.
• An operation may exhibit different behaviour
in different instances depends upon the data
types used in the operation.
• Example: addition operation
– If two numbers, will generate a sum
– If two strings, will generate a concatenation
• Extensively used in implementing inheritance
Shape
Draw ( )
Box Object
Draw ( )
Triangle Object
Draw ( )
Circle Object
Draw ( )
DYNAMIC BINDING
• The code associated with a given procedure
call is not known until the time of the call at
run time.
• Associated with polymorphism and
inheritance.
• Example: (above diagram) Unique to each
object and so the draw procedure will be
redefined in each class that defines the object.
• At run-time, the code matching the object
under current reference will be called.
MESSAGE PASSING
• Object oriented program consist of a set of
objects communicate with each.
• Steps:
– Creating classes that define objects and their behaviour.
– Creating objects from class definitions.
– Establishing communication among objects.
• Objects communicate with one another by
sending and receiving information.
• Message passing involves: object’s name,
function’s name (message) and information
BENEFITS OF OOP
• Through inheritance, we can eliminate redundant code
and extend the use of existing classes.
• The principle of data hiding helps the programmer to
build secure programs.
• Can be easily upgraded from small to large systems.
• Software complexity can be easily managed.
• "Don't Repeat Yourself" (DRY) principle is about reducing the repetition of
code.
Summary
● How OOPS evolved
● OOP paradigm elements
● Applying OOPS concepts
● Benefits of using OOPS
Advantage of OOPs over Procedure-oriented programming language
1) OOPs makes development and maintenance
easier, whereas, in a procedure-oriented
programming language, it is not easy to
manage if code grows as project size
increases.
2) OOPs provides data hiding, whereas, in a
procedure-oriented programming language,
global data can be accessed from anywhere.
Difference B/W C and Java
C is a middle-level language. Java is a high-level language.
C is a structural and procedure-
oriented programming language.
Java is an object-
oriented programming language
top-down approach to design the
application.
bottom-up approach to design the
application.
It is a compiled language. It is an interpreted language.
It is platform dependent. It is platform-independent
The file is saved with the extension .c. The file is saved with the
extension .java.
It supports the concept of the pointer. It does not support the concepts of
pointers because of security.
Exception handling is not present in
C language.
Exception handling is present in Java.
There is no concept of threading. It supports the concept of threading.
It generates .exe file. It generates .class file.
It directly executes the code. It executes code with the help of JVM.
It supports the goto
statement.
It does not support the goto
statement.
Preprocessors are supported
in C.
Preprocessors are not
supported in Java.
It is mainly used to
develop system
applications and firmware.
It is mainly used to
develop enterprise
applications and web-based
applications.
It does not maintain memory,
internally.
It maintains memory,
internally.
public class Main
{
int x = 5;
public static void main(String[] args)
{
Main myObj = new Main();
System.out.println(myObj.x);
}
}

Fundamentals of Java-Programming -Covers OOPS Concepts

  • 1.
    Course : FUNDAMENTALSOF JAVA PROGRAMMING Module 1 : JAVA BASICS Topic : Review of Object Oriented Concepts Faculty : S. Karthikeyini S Sri Ramakrishna Institute of Technology, Coimbatore Assistant Professor/CSE SRI RAMAKRISHNA INSTITUTE OF TECHNOLOGY [Educational Service: SNR Sons Charitable Trust] [Autonomous Institution, Reaccredited by NAAC with ‘A’ Grade] [Approved by AICTE New Delhi, Permanently Affiliated to Anna University, Chennai]
  • 2.
    Objective ● Programming Paradigms ●OOPS Concepts ● Benefits
  • 3.
    SOFTWARE EVOLUTION Layers ofsoftware technology Object Oriented Programming Procedure Programming Assembly Language Machine Language 1, 0
  • 4.
    A LOOK ATPROCEDURE-ORIENTED PROGRAMMING Main Program Function 1 Function 8 Function 6 Function 4 Function 5 Function 3 Function 2 Function 7
  • 5.
    Global Data GlobalData Function 1 Local Data Function 1 Local Data Function 1 Local Data Some characteristics: • Emphasis is on doing things (algorithms) • Large programs are devided into smaller programs known as function/ subrutin • Most of the function share global data • Data move openly around the system from function to function
  • 6.
  • 7.
    BASIC CONCEPTS OFOOP • · Objects • · Classes • · Data abstraction • · Encapsulation • · Inheritance • · Polymorphism • · Dynamic binding • · Message passing
  • 8.
    Some of OOP’sstriking features: ▪ Emphasis is on data rather than procedure. ▪ Programs are divided into objects. ▪ Data structures are designed such that they characterize the objects. ▪ Functions are tied together in the data structures. ▪ Data is hidden and can not be accessed by external functions.
  • 9.
    CLASSES • It isa blueprint from which objects are created • A collection of objects of similar type • Example: – Object mango, apple, and orange is member of class fruit
  • 10.
    OBJECTS • It isan instance of a class. • Have a life cycle. • They can be created and destroyed. • Interacts by sending message to one another • Contains data and code/ function to manipulate the data
  • 11.
  • 12.
    DATA ABSTRACTION • Theact of representing essential features without including the background details or explanations.
  • 13.
    ENCAPSULATION • Wrapping upof data and functions into a single unit (called class). • The data is not accessible to the outside world and only functions which are wrapped in the class can access it. • Insulation of the data from direct access by the program is called data hiding
  • 14.
    INHERITANCE • Is theprocess by which objects of one class acquire the properties of objects of another class. • Supports the concepts of hierarchical classification. • Provides the idea of reusability.
  • 15.
    Bird Attributes: Feathers Lay eggs Flying Bird Attributes: _________ _________ NonFlying Bird Attributes: _________ Robin Attributes: _________ _________ Swallow Attributes: _________ _________ Penguin Attributes: _________ _________ Kiwi Attributes: _________ _________ • Example: the bird robin is a part of the class flying bird which is again a part of the class bird.
  • 16.
    POLYMORPHISM • The abilityto take more than one form. • An operation may exhibit different behaviour in different instances depends upon the data types used in the operation. • Example: addition operation – If two numbers, will generate a sum – If two strings, will generate a concatenation • Extensively used in implementing inheritance
  • 17.
    Shape Draw ( ) BoxObject Draw ( ) Triangle Object Draw ( ) Circle Object Draw ( )
  • 18.
    DYNAMIC BINDING • Thecode associated with a given procedure call is not known until the time of the call at run time. • Associated with polymorphism and inheritance. • Example: (above diagram) Unique to each object and so the draw procedure will be redefined in each class that defines the object. • At run-time, the code matching the object under current reference will be called.
  • 19.
    MESSAGE PASSING • Objectoriented program consist of a set of objects communicate with each. • Steps: – Creating classes that define objects and their behaviour. – Creating objects from class definitions. – Establishing communication among objects. • Objects communicate with one another by sending and receiving information. • Message passing involves: object’s name, function’s name (message) and information
  • 20.
    BENEFITS OF OOP •Through inheritance, we can eliminate redundant code and extend the use of existing classes. • The principle of data hiding helps the programmer to build secure programs. • Can be easily upgraded from small to large systems. • Software complexity can be easily managed. • "Don't Repeat Yourself" (DRY) principle is about reducing the repetition of code.
  • 21.
    Summary ● How OOPSevolved ● OOP paradigm elements ● Applying OOPS concepts ● Benefits of using OOPS
  • 22.
    Advantage of OOPsover Procedure-oriented programming language 1) OOPs makes development and maintenance easier, whereas, in a procedure-oriented programming language, it is not easy to manage if code grows as project size increases. 2) OOPs provides data hiding, whereas, in a procedure-oriented programming language, global data can be accessed from anywhere.
  • 23.
    Difference B/W Cand Java C is a middle-level language. Java is a high-level language. C is a structural and procedure- oriented programming language. Java is an object- oriented programming language top-down approach to design the application. bottom-up approach to design the application. It is a compiled language. It is an interpreted language. It is platform dependent. It is platform-independent The file is saved with the extension .c. The file is saved with the extension .java. It supports the concept of the pointer. It does not support the concepts of pointers because of security. Exception handling is not present in C language. Exception handling is present in Java. There is no concept of threading. It supports the concept of threading. It generates .exe file. It generates .class file. It directly executes the code. It executes code with the help of JVM.
  • 24.
    It supports thegoto statement. It does not support the goto statement. Preprocessors are supported in C. Preprocessors are not supported in Java. It is mainly used to develop system applications and firmware. It is mainly used to develop enterprise applications and web-based applications. It does not maintain memory, internally. It maintains memory, internally.
  • 25.
    public class Main { intx = 5; public static void main(String[] args) { Main myObj = new Main(); System.out.println(myObj.x); } }