0% found this document useful (0 votes)
3 views

Java Chapter 1

This document is an introduction to Object Oriented Programming (OOP) using Java, covering fundamental concepts such as classes, objects, encapsulation, inheritance, and polymorphism. It outlines the history of programming, various programming approaches, and the importance of OOP in software development. The document emphasizes the benefits of OOP, including modularity, reusability, and improved collaboration.

Uploaded by

bahamusawer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Java Chapter 1

This document is an introduction to Object Oriented Programming (OOP) using Java, covering fundamental concepts such as classes, objects, encapsulation, inheritance, and polymorphism. It outlines the history of programming, various programming approaches, and the importance of OOP in software development. The document emphasizes the benefits of OOP, including modularity, reusability, and improved collaboration.

Uploaded by

bahamusawer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Introduction to Object Oriented

Programming (Java)
Maiwand University
Faculty of Computer Science
Chapter 1

Lecturer: Ajmal Sahak


May 2025
Contents

• What is Programming
• History of Programming
• Programming Approaches
• Object Oriented Programming
• Importance of OOP
• Class and Object
• Properties and Methods in Objects
• Object Relationships in OOP
• Core Principles of OOP
• Encapsulation
• Inheritance
• Polymorphism
What is Programming

• Programming is the process of giving instructions to a computer to


perform specific tasks.
• It allows humans to communicate with computers using programming
languages.
• Programming languages follow specific rules (syntax) to write clear and
logical instructions.
• Programs are used to solve problems, automate tasks, and build
software, websites, games, and more.
• Learning programming helps develop problem-solving, logical thinking,
and creativity.
• Popular programming languages include C, C++, Java, Python etc.
History of Programming
• Programming began in the early 19th century with Ada Lovelace,
considered the first programmer.
• The first computers used machine code and punch cards.
• Programming evolved from assembly language to high-level languages.
• Key milestones: FORTRAN (1957), COBOL (1959), C (1972), C++ (1983),
Python (1991), Java (1995) and more.
• Java was developed by James Gosling and his team at Sun Microsystems
in 1995.
• It was designed to be platform-independent, allowing programs to run on
any device with a Java Virtual Machine (JVM).
• Originally called Oak, it was later renamed Java.
• In 2009, Oracle Corporation acquired Sun Microsystems and now
maintains Java. Today, it's widely used for web, mobile, and enterprise
applications.
Programming Approaches
• Software is developed to solve real-world problems using device
capabilities. With evolving hardware (not just computers), software
development methods also changed.
• This change led to different approaches in programming.

• Key approaches in programming are as follows:

 Procedural Programming: Based on step-by-step procedures or routines


(functions). Focuses on how a task is performed. Common in early languages
like C, Pascal, Fortran.
 Object-Oriented Programming (OOP): Models software as interacting objects
based on real-world entities. Uses concepts like classes, inheritance, and
encapsulation. Common in Java, Python, C++.
 Structured Programming: Emphasizes clear control flow (sequence, selection,
loops). Subset of procedural programming with better structure like C, Ada.
 Component-Based Development, Aspect-Oriented Programming (AOP) etc.
Object Oriented Programming
• OOP emerged in the late 1960s to manage increasing complexity and
maintenance costs.

• It models software using real-world entities through Classes, Objects,


Encapsulation, Inheritance, Polymorphism.

• OOP uses real-world objects and their relationships to build models. The
approach mimics human thinking and specialization, making it highly
productive.

• In OOP: Class = factory / Object = product


• These are the core concepts of the object-oriented programming
approach.

• Benefits: Modularity, Reusability, Maintainability.


Importance of OOP

• Maintenance (Easy to Update): Code is organized into classes, so changes are


isolated. Updates or bug fixes can be made without affecting the entire system.
• Extensibility (Easy to Expand): New features can be added by extending existing
classes.
• Reusability (Use Again, Save Time): Well-designed classes can be stored in shared
libraries. Developers can reuse existing components instead of rewriting code.
• Improved Collaboration: Teams can work on different classes/modules
independently. Encourages specialization and cleaner code organization.
• Closer to Real-World Modeling: Objects and classes mimic real-life entities and
relationships. Makes system design more intuitive and easier to understand.
Understanding Classes and Objects
• A class is a blueprint or template that defines the common features
(properties) and behaviors (methods) of a group of similar items.

• An object is a specific instance of a class with real values assigned to its


properties.

• Example:
 Class: Car (defines engine, wheels, accelerate, brake)
 Object: A specific car with plate number “26 AA 001”
 Objects are created based on the class and share the class-defined
behaviors.
Properties and Methods in Objects
• Objects have properties (data like speed, color) and methods (actions like
drive, stop).
• Methods change the state of an object by updating its properties.

• Example (Car object):


 Properties: speed = 50 km/h, gear = 3, fuel = 60%
 Methods: accelerate(), brake(), stop()

• Methods make the object act like a real-life item, enabling interaction and
behavior changes.
Object Relationships in OOP
• Objects can relate to each other through different relationships:
• Association (has-a): One object contains or uses another.
 e.g., A Pencil Case has Pencil objects.
• Dependency (uses-a): e.g., A Car depends on Wheels to function.
• One object needs another to work.

• These relationships reflect how real-world entities interact, making


systems more intuitive and modular.
Core Principles of OOP
• Encapsulation: Hides internal details and exposes only what’s necessary.

• Inheritance: Allows new classes to inherit features from existing ones.

• Polymorphism: Enables different objects to respond to the same message


in different ways.
Encapsulation
• Encapsulation means hiding internal details of a class and exposing only
what’s necessary.
• Ensures that each object maintains a valid and consistent state.
• Initial values and setup are handled through constructors.
• Keeps internal features private to protect data and ensure system
integrity.
• Exposes only the necessary methods and properties to external classes.
Prevents unintended access and changes by limiting visibility.
• How It’s Done:
• Uses access modifiers like public, private, protected to control access:
• Real-Life Analogy:
• Like a TV: common buttons (volume, channel) are visible and usable by
anyone (public).Advanced settings (color, contrast) are hidden behind a
cover—only accessible to users who know how (private/protected).
Inheritance
• Inheritance allows a class to acquire properties and methods from another
class.
• Enables code reuse, reduces redundancy, and supports easier extension of
functionality.
• Key Concepts:
 Base Class (Superclass): The class being inherited from.
 Derived Class (Subclass): The class that inherits features from the base
class.
• Real-Life Analogy: Animal class → common traits (e.g., breathing, eating).
 Mammals, Reptiles, Birds → inherit from Animal and add their own
specific traits.
• Multiple Inheritance:
 A class can inherit from more than one class (e.g., a Truck inheriting
from both Vehicle and TowingMachine).
 Supported in C++, but not directly in Java. In Java, multiple inheritance
is achieved using interfaces and abstract classes.
Polymorphism
• Polymorphism allows objects to perform the same operation in different ways,
depending on their class.
• The same method can act differently based on the object calling it.
• Different Behaviors, Same Interface: Classes may have methods with the same
name but different implementations. Objects of subclasses can be treated as
objects of the parent class.
• Real-Life Example: Printer Example: A Printer class with a print() method. Color
Printer: Prints in color. Black & White Printer: Prints in black and white. Both use
the same print() method but produce different results.
• Why is it Useful?
 Simplifies Code: You don't need to know the specific class of an object, just call the
same method.
 Flexibility: Allows new classes to be added without altering existing code.
Thank You

You might also like