0% found this document useful (0 votes)
12 views23 pages

OOP Chapter 1

The document provides an introduction to Object-Oriented Programming (OOP) and Java, explaining key concepts such as programming, programming languages, and various programming paradigms. It details the core principles of OOP, including encapsulation, inheritance, polymorphism, and abstraction, as well as the characteristics and applications of Java. Additionally, it covers the Java development environment, compilation process, and the importance of garbage collection in memory management.

Uploaded by

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

OOP Chapter 1

The document provides an introduction to Object-Oriented Programming (OOP) and Java, explaining key concepts such as programming, programming languages, and various programming paradigms. It details the core principles of OOP, including encapsulation, inheritance, polymorphism, and abstraction, as well as the characteristics and applications of Java. Additionally, it covers the Java development environment, compilation process, and the importance of garbage collection in memory management.

Uploaded by

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

Introduction to

Object Oriented
Programming(OOP)

📍 Instructor: Ketema D.(MSc in Computer Science and Engineering)


What is Programming?
 Programming is the process of writing instructions (code) that a computer
can understand and execute to perform specific tasks. Or
 A program is a set of instructions written in a programming language
Many Aspects of Programming
 Programming involves multiple aspects:
 Problem-Solving: Finding optimal solutions, like the best travel route.
 Control: Instructing the computer to perform tasks precisely as directed.
 Teaching: The computer learns only what it's explicitly told.
 Creativity: Developing effective solutions from many possible options.
 Modeling: Representing the key properties and behaviors of a system.
 Abstraction: Focusing on essential features while avoiding unnecessary
details.
What is Programming?
 Why Learn Programming?
✅ Automate tasks and solve problems
✅ Develop software and applications
✅ Understand how technology works
📝 Example:
🔹 Everyday applications like WhatsApp, Google Search, and Banking Apps are built
using programming languages!
A program works through the following concise steps

1.Writing Code – A programmer writes instructions using a programming


language (e.g., Python, Java).
2.Compilation/Interpretation – The code is translated into machine language
(binary) by a compiler or interpreter.
3.Loading into Memory – The OS loads the program into RAM for execution.
4.Execution – The CPU processes instructions sequentially, interacting with
memory, input, and output.
5.Output Generation – The program produces results, such as displaying text,
saving files, or controlling hardware.
6.Termination – The program completes execution or waits for further input
Programming Languages
1. Machine language
 computer’s native language, sequence of zeroes and ones (binary)
 hard for humans to understand: 01010001…
2. Assembly language
mnemonics for machine language
Easier to read than machine language but still requires knowledge of hardware.
Each instruction directly corresponds to a machine language instruction.
MOV AX, 5 ; Move the value 5 into register AX
ADD AX, BX ; Add the value in register BX to AX
3. High-level languages
FORTRAN, Pascal, BASIC, C, C++, Java, etc.
high level: each instruction composed of many low-level instructions
closer to English easier to read and understand:
sum = a + b
print("The sum is:", sum)
or

int sum = a + b;
System.out.println("The sum is: " + sum);
Types of Programming Paradigms
📌 A programming paradigm is a way of writing and organizing code.
🔹 Types of Programming Paradigms:
1️⃣ Procedural Programming
2️⃣ Logical Programming
3️⃣ Functional Programming
4️⃣ Object-Oriented Programming (OOP)

1. Procedural Programming (Step-by-Step Approach)


A programming paradigm where the program is written as a sequence of instructions
(procedures or functions).
🔹 Characteristics:
✅ Uses functions to structure code
✅ Follows a top-down approach
✅ Focuses on step-by-step execution
✅ Used In: C, Pascal, Java (partially)
...
2. Logical Programming (Rule-Based)
 A paradigm where programs consist of facts and rules, and the computer derives
conclusions using logical reasoning.

🔹 Characteristics:
✅ Uses declarative statements (what to do, not how to do)
✅ Focuses on relations and rules
✅ Common in AI and Expert Systems

📝 Example (Prolog - Logical Programming):


Father(Tolcha, Chala).
Father(Chala, Tolasa).

grandFather(X, Y) :- Father(X, Z), Father(Z, Y).

✅ Used In: Prolog, Datalog


...
3. Functional Programming (FP)
 A paradigm where programs are built using pure functions, avoiding changing state
(mutability) and side effects.
🔹 Characteristics:
✅ Treats functions as first-class citizens
✅ Focuses on immutable data
✅ Uses pure functions
📝 Example (Java - Functional Style using Lambda Expressions):

calculateArea :: Int -> Int -> Int


calculateArea length width =
let area = length * width
in area

main = print (calculateArea 5 3) -- Output: 15

✅ Used In: Java 8+, Scala, Kotlin and Haskell



3. Object-Oriented Programming(OOP)

 A programming paradigm based on the concept of "objects."


 Objects: Instances of classes that encapsulate data and behavior.
 Class : A blueprint for creating objects
 Example
 Class: A blueprint for creating objects (e.g., class Car).
 Object: An instance of a class (e.g., myCar = Car()).
 Attributes: Variables that store data (e.g., color, model).
 Methods: Functions that define behavior (e.g., drive(), brake()).
Core Principles of OOP
Encapsulation:
 Bundling data (attributes) and methods (functions) into a single unit
(class).
 Protects data by restricting direct access (e.g., private/public modifiers).
Inheritance:
• Allows a class (child) to inherit properties and methods from another
class (parent).
• Promotes code reuse and hierarchical classification.
Polymorphism:
 Enables objects to take on multiple forms (e.g., method overriding or
overloading).
 Allows flexibility in calling methods on different objects.
1.Abstraction:
 Hides complex implementation details and exposes only essential
features.
 Achieved through abstract classes and interfaces.

💡 These principles make code more modular, reusable, and maintainable.


….
🚀 Advantages of OOP Over Other Paradigms:
✅ More organized and reusable code
✅ Easier to maintain and scale
✅ Better security with encapsulation
✅ Widely used in software development
Introduction to Java language

Java is a high-level, object-oriented programming language.


•Developed by Sun Microsystems (now owned by Oracle).
•Used in web, mobile, enterprise, and embedded systems development.

History of Java
1991 – Started as "Oak" by James Gosling & team at Sun Microsystems.
1995 – Renamed to Java and officially released.
1996 – First stable Java version (JDK 1.0).
2006 – Open-sourced as OpenJDK.
2010 – Oracle acquired Sun Microsystems.
Present – Java is widely used in enterprise applications, cloud computing, and Android
development.
Java version, read:
https://www.oracle.com/java/technologies/downloads/?er=221886
Characteristics of Java Programming
1. Platform-Independent
•Follows "Write Once, Run Anywhere" (WORA) using Java Virtual Machine
(JVM).

2. Object-Oriented
•Based on OOP principles: Encapsulation, Inheritance, Polymorphism, and
Abstraction.
3. Simple and Secure
•Easy-to-learn syntax and built-in security features like memory management
and exception handling.
Characteristics of Java Programming
4. Portable
If any language supports platform independent and architectural neutral feature is
known as portable.
So, Java is a portable language.

5. Multi-threaded
A flow of control is known as a thread.
When any Language executes multiple thread at a time that language is known as
multithreaded.
Supports concurrent execution of multiple tasks for better performance.

So, Java is multithreaded.


Characteristics of Java Programming.
6. Distributed Computing in Java
Java enables distributed applications.
Technologies: RMI & EJB.
Key Benefit: Clients depend on multiple servers—failure in one does not affect others.
system.
Characteristics of Java Programming
7. Robust
Robust simply means strong.
It is robust or strong Programming Language because of its capability to
handle Run-time Error, automatic garbage collection, the lack of pointer
concept, Exception Handling. All these points make It robust Language.
8. Dynamic
It supports Dynamic memory allocation
The process of allocating the memory space to the input of the program at
a run-time is known as dynamic memory allocation
Characteristics of Java Programming

9. Object Oriented

 It supports OOP's
 In java everything is Object which has some data and
behavior.
 Java can be easily extended as it is based on Object Model.
Java Development Environment

To write and run Java programs, you need:


•JRE (Java Runtime Environment) – Allows Java programs to run on any
device.
•JDK (Java Development Kit) – Includes Java Compiler, JVM, JRE and
development tools.
also called System Development Kit (SDK).
•JVM (Java Virtual Machine) – Converts Java bytecode into machine code
for execution.
What is Java Used For?

Common applications include:


1.Game Development – Used in mobile, PC, and VR games, integrating
technologies like AI and machine learning.
2.Cloud Computing – Its Write Once, Run Anywhere (WORA) capability
makes it ideal for cloud-based applications.
3.Big Data – Powers data processing engines for handling massive real-
time datasets.
4.Artificial Intelligence – Supports AI applications like natural language
processing (NLP) and deep learning with its speed and stability.
5.Internet of Things (IoT) – Enables programming of smart sensors and
edge devices that connect to the internet.
….
Editing, Compiling, and Interpreting programming Code(in Java)

📌 Steps in Java Development:

1️⃣ Editing – Writing the Java program in an editor (e.g., VS Code, IntelliJ, Eclipse).
2️⃣ Compiling – Converting Java code (.java) into bytecode (.class).
3️⃣ Interpreting – The JVM interprets and executes bytecode on different platforms.
Java Compilation Process
🔹 Java Code → Compilation → Bytecode → Interpretation

✅ Java Compiler (javac) → Converts .java file to .class (bytecode).


✅ Java Virtual Machine (JVM) → Interprets and executes the bytecode.
✅ Cross-Platform → Write once, run anywhere!
💡 Java is both compiled (to bytecode) and interpreted (by JVM).
….
what does JVM performs?
 It is used to load the code.
 It Verifies and executes the code. And
 it provides run time environment.

What is Bytecode in Java?


 Bytecode is an intermediate representation of Java code, generated after
compilation.
 It is not machine-specific, making Java platform-independent.
 Bytecode is executed by the Java Virtual Machine (JVM).

Why is JVM Important?


 Converts Bytecode into Machine Code for execution.
 Provides platform independence (Java runs on any OS with a
JVM).
 Handles memory management (Garbage Collection).
 Ensures security by running programs in a controlled
environment.
What is Garbage Collection in OOP?

What is Garbage in Java?


 Garbage refers to objects that are no longer referenced or accessible by the
program.
 These objects are considered "unused" and can be cleaned up by the garbage
collector.
What is Garbage Collection?
•Garbage Collection (GC) is an automatic memory management process in Java.
•It identifies and removes objects that are no longer needed, freeing up memory
space.
Why is Garbage Collection Important?
•Memory Management: Ensures efficient use of memory by removing unused
objects.
•Prevents Memory Leaks: Frees up memory that would otherwise be wasted.
•Reduces Programmer Overhead: No need to manually manage memory, reducing
complexity.
•Improves Performance: Keeps applications running smoothly and efficiently.
Reading
How Does Java Choose When to Run GC?
Means, How does Java determine when to run garbage collection
automatically?
End of Part -I

You might also like