You are on page 1of 1

Lesson 1: Introduction to OOP 2.

Objects respond only to messages

What is OOP? Java is an object-oriented programming language.

OOP stands for Object-Oriented Programming. OOP is a Everything in Java is associated with classes and objects,
programming style which is associated with the concepts like along with its attributes and methods.
class, object, inheritance, encapsulation, abstraction, and
For example: in real life, a car is an object. The car has
polymorphism. Most popular programming languages like
attributes, such as weight and color, and methods, such as
Java, C++, C#, Ruby, VB.Net etc. follow an object oriented
drive and brake.
programming paradigm.
A Class is like an object constructor, or a "blueprint" for
Procedural programming is about writing procedures or
creating objects.
methods that perform operations on the data, while object-
oriented programming is about creating objects that contain
both data and methods. Create an Object
Object-oriented programming has several advantages over In Java, an object is created from a class. We have already
procedural programming: created the class named MyClass, so now we can use this to
create objects.
 OOP is faster and easier to execute
 OOP provides a clear structure for the programs To create an object of MyClass, specify the class name,
 OOP helps to keep the Java code DRY "Don't Repeat followed by the object name, and use the keyword new:
Yourself", and makes the code easier to maintain,
 Multiple Objects You can create multiple objects of
modify and debug
one class:
 OOP makes it possible to create full reusable
 Using Multiple Classes
applications with less code and shorter development
time  You can also create an object of a class and access it
in another class. This is often used for better
Tip: The "Don't Repeat Yourself" (DRY) principle is about organization of classes (one class has all the
reducing the repetition of code. You should extract out the attributes and methods, while the other class holds
codes that are common for the application, and place them  the main() method (code to be executed)).
at a single place and reuse them instead of repeating it.  Remember that the name of the java file should
match the class name. In this example, we have
What are the four basic principles/ building blocks of OOP
 created two files in the same directory/folder:
(object oriented programming)?

The building blocks of object-oriented programming are


Inheritance, Encapsulation,

What are the benefits of Object Oriented Programming?

1. Improved productivity during software development

2. Improved software maintainability

3. Faster development sprints

4. Lower cost of development

5. Higher quality software

However, there are a few challenges associated with OOP,


namely:

1. Steep learning curve

2. Larger program size

3. Slower program execution

4. It’s not a one-size fits all solution

Two main principles of Object Oriented Programming

1. Everything is an Object

You might also like