Chapter 1 PDF
Chapter 1 PDF
Chapter 1 PDF
Learning Objectives
After the completion of the chapter, students will be able to:
explain what is object-oriented programming and its basic concepts;
discuss the advantage of OOP in developing a program; and
declare identifiers such as class, package, variable, constant, and method
following the Java naming convention.
Object means a real-world entity such as a pen, chair, table, computer, and watch. Object-
oriented programming is a methodology or paradigm to design a program using classes
and objects. It simplifies software development and maintenance.
Any entity that has state and behavior is known as an object. For example, a chair, pen,
table, keyboard, and bike. It can be physical or logical. An object can be defined as an
instance of a class. An object contains an address and takes up some space in memory.
Objects can communicate without knowing the details of each other's data or code. The
only necessary thing is the type of message accepted and the type of response returned
by the objects.
Example A dog is an object because it has state like color, name, and breed, as well as
behaviors like wagging the tail, barking, and eating.
A collection of objects is called a class. It is a logical entity. A class can also be defined as
a blueprint from which you can create an individual object. Class doesn’t consume any
space.
When one object acquires all the properties and behaviors of a parent object, it is known
as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.
Hiding internal details and showing functionality is known as abstraction. For example,
we do not know the internal processing that occurs during a phone call. In Java, we use
abstract class and interface to achieve abstraction.
Binding (or wrapping) code and data together into a single unit is known as
encapsulation. A Java class is an example of encapsulation.
OOP provides the ability to simulate real-world event much more effectively.
Object-based programming language follows all the features of OOPs except inheritance.
JavaScript and VBScript are examples of object-based programming languages.
All the classes, interfaces, packages, methods and fields of Java programming language
are given according to the Java naming convention. If you fail to follow these conventions,
it may generate confusion or erroneous code.
By using standard Java naming conventions, you make your code easier to read for
yourself and other programmers. Readability of Java program is very important. It
indicates that less time is spent to figure out what the code does. The following are the
key rules that must be followed by every identifier: