Chapter 1
Introduction to Object-Oriented Programming
1. Introduction
Object-oriented programming (OOP) is a computer programming model that organizes software
design around data, or objects, rather than functions and logic. An object can be defined as a data
field that has unique attributes and behavior.
OOP focuses on the objects that developers want to manipulate rather than the logic required to
manipulate them. This approach to programming is well suited for software that is large,
complex and actively updated or maintained. This includes programs for manufacturing and
design, as well as mobile applications. For example, OOP can be used for manufacturing system
simulation software.
The organization of an object-oriented program also makes the method beneficial for
collaborative development, where projects are divided into groups. Additional benefits of OOP
include code reusability, scalability and efficiency.
The first step in OOP is to collect all of the objects a programmer wants to manipulate and
identify how they relate to each other -- an exercise known as data modeling.
Examples of an object can range from physical entities, such as a human being who is described
by properties like name and address, to small computer programs, such as widgets.
Once an object is known, it is labeled with a class of objects that defines the kind of data it
contains and any logic sequences that can manipulate it. Each distinct logic sequence is known as
a method. Objects can communicate with well-defined interfaces called messages
Java is a high-level, robust, object-oriented, and secure programming language. It was developed
by Sun Microsystems in 1995 and later acquired by Oracle. The father of Java, James Gosling,
initially named it "Oak" before renaming it to "Java." Java is both a programming language and a
platform that provides a runtime environment and libraries to facilitate application development.
Example:
public class HelloWorld {
public static void main(String[] args) {
[Link]("Hello, World!");
}
}
1
This simple Java program prints "Hello, World!" to the console.
The structure, or building blocks, of object-oriented programming include the following:
Classes are user-defined data types that act as the blueprint for individual objects, attributes and
methods.
Objects are instances of a class created with specifically defined data. Objects can correspond to
real-world objects or an abstract entity. When class is defined initially, the description is the only
object that is defined.
Methods are functions that objects can perform. They are defined inside a class that describe the
behaviors of an object. Each method contained in class definitions starts with a reference to an
instance object. Additionally, the subroutines contained in an object are called instance methods.
Programmers use methods for reusability or keeping functionality encapsulated inside one object
at a time.
Attributes represent the state of an object. In other words, It is the characteristics that
distinguish classes. Objects have data stored in the attributes field. Class attributes belong to the
class itself and are defined in the class template.
2. Types of Java Applications
Java supports multiple application types, including:
2.1 Standalone Applications
Also known as desktop applications or window-based applications, these traditional software
applications require installation on individual machines. Examples include media players,
antivirus software, and text editors. Java provides AWT and Swing libraries to create such
applications.
2.2 Web Applications
Web applications run on web servers and generate dynamic content. A web application is a
software application that runs on a web server and is accessed through a web browser over the
internet or an intranet. Unlike standalone applications, web applications do not require
installation on the client-side.
Java is a widely used technology for developing web applications due to its platform
independence, security, scalability, and rich set of libraries. Java provides several
frameworks and technologies for web development, including:
Servlets
JavaServer Pages (JSP)
2
Spring Framework
JavaServer Faces (JSF)
Hibernate (for database handling)
2.3 Enterprise Applications
Enterprise applications are large-scale, distributed applications such as banking systems and
customer management solutions. Java supports enterprise development using technologies like
Enterprise JavaBeans (EJB) and Spring Boot. Enterprise applications are large-scale, distributed
applications designed to meet the needs of organizations such as banks, healthcare providers, and
government institutions. These applications handle huge amounts of data, support multiple users,
and ensure high security and performance.
Java is widely used for enterprise application development because of its scalability, security,
reliability, and cross-platform capabilities. Technologies such as Enterprise JavaBeans (EJB),
Spring Boot, Hibernate, and Java EE help in developing robust enterprise solutions.
2.4 Mobile Applications
Mobile applications are designed to run on mobile devices. Java ME (Micro Edition) and
Android (which uses Java as a primary language) are commonly used for developing mobile
applications.
Mobile applications are designed to run on smartphones, tablets, and other mobile devices.
Java is one of the most popular languages for mobile application development, especially with
Android development.
There are two primary Java-based technologies for mobile development:
1. Java ME (Micro Edition) – Used for embedded and lightweight mobile applications.
2. Android Development – Uses Java as a primary language along with the Android SDK.
Java is widely used for mobile development because it is cross-platform, object-oriented,
secure, and has extensive libraries and frameworks
Java ME (Micro Edition)
Java ME is a lightweight version of Java designed for mobile devices, embedded systems, and
IoT devices. It provides a set of APIs and a runtime environment for resource-constrained
devices.
Features of Java ME
Supports Connected Limited Device Configuration (CLDC) for small devices.
3
Provides Mobile Information Device Profile (MIDP) for mobile applications.
Applications run in a sandboxed environment, ensuring security.
3. Programming Paradigm
A programming paradigm is a fundamental style of programming that dictates how solutions are
structured. Java follows the Object-Oriented Programming (OOP) paradigm, which models real-
world entities and interactions using objects and classes.
3.1 Unstructured Programming
Unstructured programming languages do not have such specific rules or structures. They are
typically written as a series of commands or statements, which are executed from top to bottom.
This can make the code harder to read and understand, especially for larger programs.
Unstructured programming languages are often used for scripting or quick-and-dirty tasks, where
the simplicity of the language allows for rapid development. Unstructured programming
languages, while simpler and easier to learn, can lead to messy and inefficient code if not used
properly. Additionally, understanding different programming paradigms can help clarify why
structured languages are favored for complex and scalable software development. It is the
simplest form of programming, where code is written in a single sequence, usually in one large
function. It lacks modularity and scalability. Examples of unstructured programming languages
include Assembly and early versions of BASIC. These languages tend to focus more on
fundamental programming constructs and direct manipulation of hardware
3.2 Procedural Programming
Procedural programming language makes use of a step by step approach for breaking down a
task into a collection of routines (or subroutines) and variables by following a sequence of
instructions. It carries out each step systematically in order so that a computer easily gets to
understand what to do. It’s derived from structural programming. It follows the concept of the
calling procedure. The procedures, also called functions, routines, or subroutines, consist of a
series of computational steps that they need to carry out. During the execution of a program, one
can call any given procedure at any point- either by other procedures or by itself. Procedural
programming organizes code into functions or procedures that execute sequentially. Procedural
Programming does not offer any method of hiding data. Thus, it is less secure when compared to
Object Oriented Programming. Languages like BASIC, FORTRAN, COBOL, ALGOL, Pascal,
and C.
3.3 Structured Programming
Structured programming languages are designed to improve the clarity, quality, and development
time of a computer program by making extensive use of subroutines, block structures, for and
4
while loops. They follow a top-down design approach, where a system is divided into
compositional subsystems. This approach allows for control structures like sequences, loops, and
decisions, which guide the order in which instructions are executed. Examples of structured
programming languages include C, Java, and Python. Structured programming languages
encourage a more organized and systematic approach to programming, which can lead to more
reliable and maintainable code. They also tend to be more powerful and flexible, allowing for
more complex programs to be written. For a broader view, explore the topic of fundamental
computer operations. Structured programming is an extension of procedural programming that
enforces logical structures and modular design. It improves code readability and maintainability.
3.4 Object-Oriented Programming (OOP)
Object Oriented Programming as a programming model that follows the concept of objects. The
objects contain codes in the form of methods and data in the form of attributes. In the case of
Object Oriented Programming, it designs computer programs by using the concept of the objects
interacting with the real world. There are various Object Oriented Programming languages.
Programming language uses objects and classes for creating models based on the real-world
environment. This model makes it very easy for a user to modify as well as maintain the existing
code while new objects get created by inheriting the characteristics of the present ones. But the
most popular ones among all are class-based. It means that the objects are instances of the
classes determining their types. Object-oriented programming is based on the concept of objects,
which encapsulate data and behavior. Java is fundamentally an OOP language that supports
modularity, reusability, and scalability. Hiding data is possible with Object Oriented
Programming due to the abstraction. Thus, it is more secure than the Procedural Programming.
Object Oriented Programming Languages – Java, Python, C#, C++, JavaScript, PHP, Ruby,
Dart, Perl, Swift, Scala, Objective.
4. Object-Oriented Principles
Java adheres to four core principles of OOP:
4.1 Polymorphism
Polymorphism enables a single interface to support multiple implementations. It allows methods
to perform different tasks depending on the object that calls them. Objects are designed to share
behaviors, and they can take on more than one form. The program determines which meaning or
usage is necessary for each execution of that object from a parent class, reducing the need to
duplicate code. A child class is then created, which extends the functionality of the parent class.
Polymorphism enables different types of objects to pass through the same interface.
4.2 Encapsulation
5
Encapsulation is the process of bundling data (fields) and methods (functions) into a single unit
(class) while restricting direct access to some of the object's components. Encapsulation
principle states that all important information is contained inside an object and only select
information is exposed. The implementation and state of each object are privately held inside a
defined class. Other objects do not have access to this class or the authority to make changes.
They are only able to call a list of public functions or methods. This characteristic of data hiding
provides greater program security and avoids unintended data corruption.
4.3 Inheritance
Inheritance enables one class (subclass) to acquire the properties and behaviors of another class
(superclass), promoting code reusability. Classes can reuse code and properties from other
classes. Relationships and subclasses between objects can be assigned, enabling developers to
reuse common logic, while still maintaining a unique hierarchy. Inheritance forces more
thorough data analysis, reduces development time and ensures a higher level of accuracy.
4.4 Abstraction
Abstraction hides complex implementation details and exposes only relevant functionalities,
allowing users to interact with simpler interfaces. Objects only reveal internal mechanisms that
are relevant for the use of other objects, hiding any unnecessary implementation code. The
derived class can have its functionality extended. This concept can help developers more easily
make additional changes or additions over time.
5. Java Development Environment
To develop Java applications, programmers use Integrated Development Environments (IDEs)
such as:
5.1 NetBeans
NetBeans is an open-source IDE that supports multiple languages, including Java, PHP, C++,
and HTML5.
5.2 Eclipse
Eclipse is another popular IDE for Java development, offering extensive features for software
development across different platforms.
5.3 Java Development Tools
Java provides essential tools for application development, including:
6
Javac: The Java compiler that converts source code into bytecode.
Java Interpreter: Executes Java bytecode.
Javadoc: Generates API documentation from Java source code.
Object-oriented programming is a powerful paradigm that simplifies software development by
modeling real-world entities as objects. Java, as an OOP language, supports key principles like
encapsulation, inheritance, polymorphism, and abstraction, making it a preferred choice for
various application domains, including desktop, web, enterprise, and mobile development.
With Java's extensive libraries and development tools, programmers can build efficient and
scalable applications that meet diverse industry needs.