Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Week3 PP OOP Object Classes

Uploaded by

kenz.dgzmn18
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Week3 PP OOP Object Classes

Uploaded by

kenz.dgzmn18
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Week 3 – Procedural

Programming vs Object
Oriented Programming
CCPRGG1L- Fundamentals of Programming
Opening Prayer
Heavenly Father,
We thank You and praise You! You are the everlasting God.
Please prepare our hearts and minds to learn. To the best of our
ability today.
Please bless us as we study. Please help us to grow.
May Your protection be upon us as we go about our day.
Amen
Checking of Attendance
Attendance with a TWIST
1. Nagmahal po sir
2. May crush po sir
3. Nasaktan po sir
4. Study po sir
5. Umaasa pa rin po sir
6. Nag-GHOST po sir
Let’s do a RECAP
At the end of the session, the students shall be able to:
• Understand the basic concepts of Procedural Programming and
Object-Oriented Programming
• Learn how to declare and use classes and objects in Java
Procedural Programming
Procedural Programming
• Traditional programming languages were procedural.
❖ C, Pascal, BASIC, Ada and COBOL

• Programming in procedural languages involves choosing data


structures (appropriate ways to store data), designing
algorithms, and translating algorithm into code
Procedural Programming
• In procedural programming, data and operations on the data are
separated.

• This methodology requires sending data to procedure/functions.


Procedural Programming
Characteristics of procedure-oriented
programming:
• Large programs are divided into smaller programs known as
functions.
• Most of the functions share global data.
• Data move openly around the system from function to function.
• Functions change the value of data at any time from any place.
(Functions transform data from one form to another.)
• It uses top-down approach in program design.
Drawback
• In POP, global data can be accessed & changed by any
procedure (function) so there is no data security. In case if we
want to change type of data of global data, then we also need to
resolve all functions that access the data.
• Due to this it may happened that some errors will occurs
• POP does not model real world problems because functions
are action oriented.
Object Oriented
Programming (OOP)
Object Oriented Programming
• Object-oriented programming is centered on creating
objects rather than procedures/ functions.
• Objects are a melding of data and procedures that
manipulate that data.
• Data in an object are known as attributes.
• Procedures/functions in an object are known as methods
Object Oriented Programming
• Object-oriented programming combines data and behavior (or method).This
is called encapsulation.

• Data hiding is the ability of an object to hide data from other objects in the
program.

• Only an object’s methods should be able to directly manipulate its


attributes.

• Other objects are allowed to manipulate an object’s attributes via the


object’s methods.

• This indirect access is known as a programming interface.


Object Oriented Programming
Benefits of Object-oriented programming
• Save development time (and cost) by reusing code
- once an object class is created it can be used in other applications
• Easier debugging
– classes can be tested independently – reused objects have already
been tested
Advantages of OOP:
• Improved software-development productivity
• Improved software maintainability
• Faster development
• Lower cost of development
• Higher-quality software
Object-oriented programming has several advantages over
procedural programming

1.OOP is faster and easier to execute


2.OOP provides a clear structure for the programs
3.OOP helps to keep the Java code DRY "Don't Repeat
Yourself", and makes the code easier to maintain, modify and
debug
4.OOP makes it possible to create full reusable applications
with less code and shorter development time
Disadvantages of OOP
•Large Program Size
•Effort
•Speed
Differences of Procedural
& Object Oriented
Classes & Object
Class and Instances
Class
Class is a user defined blueprint or prototype from which objects are created. It
represents the set of properties or methods that are common to all objects of one type.

Objects
Object is an instance of a class. It is a basic unit of Object-Oriented Programming and
represents the real-life entities. A typical Java program creates many objects, which as
you know, interact by invoking methods. An object consists of :

• State (Variables): It is represented by attributes of an object. It also reflects the


properties of an object.
• Behavior (Methods): It is represented by methods of an object. It also reflects the
response of an object with other objects.
• Identity (Identifier): It gives a unique name to an object and enables one object to
interact with other objects.
Class and Instances
Source: https://techvidvan.com/tutorials/java-class/
public class JavaApplication7 {

public static void main(String args) {


Scanner type = new Scanner(System.in);

System.out.printn("1st number:");
double n = type.nextDouble()

System.out.println("Enter the second number:");


double x =float.nextDouble();

double z = n+x;
System.out.println("The sum is:" +z);

}
Instantiation and Initialization
Constructors are used for initializing new objects.
Fields are variables that provides the state of the
class and its objects, and methods are used to
implement the behavior of the class and its objects

The new operator instantiates a class by allocating


memory for a new object and returning a reference to
that memory. The new operator also invokes the class
constructor
Instantiation and Initialization
References
• Dale, Nell and Weems, Chip, Introduction to Pascal and
Structured Design, 4th edition, D. C. Heath and Company,
Lexington, Massachusetts, 1994.​
• Java Objects and Classes. Retrieved
from https://www.tutorialspoint.com/java/java_object_classes.htm
• Introduction to programming. Retrieved
from https://ocw.mit.edu/courses/electrical-engineering-and-
computer-science/6-092-introduction-to-programming-in-java-
january-iap-2010/

You might also like