0% found this document useful (0 votes)
16 views38 pages

Chapter One

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)
16 views38 pages

Chapter One

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/ 38

Chapter One

Introduction To Object Oriented Programming

By Minichil A.
Basics of Programming

1 Programming: is the process of writing, testing, debugging/troubleshooting,


and maintaining the source code of computer programs.

2 Programs :are the instructions for a computer. A computer requires programs


to function; and a computer program does nothing unless a CPU executes its
instructions.

3 A programming paradigm:
 is a fundamental style of programming.
 is an approach to solve problem using some programming language.
 There are lots for programming language that are known but all of them need to follow
some strategy when they are implemented, and this methodology/strategy is paradigms

2
Types of Programming Paradigms
Procedural Programming:
 Procedural programming is a programming paradigm based upon the concept of
procedure call.
 In Procedural programming, programs are sequences of instructions to be executed.

 They focus heavily on splitting up programs into named sets of instructions called
procedures.
 Procedures, also known as routines, subroutines, methods, or functions simply contain
a series of computational steps to be carried out to solve a problem
 Procedural programming language includes: Fortran, C, Pascal
3
Object Oriented Programming:
 The program is written as a collection of classes and object which are meant for communication.
 It depends upon objects (having both data and methods) that aims to incorporate the advantages
of modularity and reusability.
 More emphasis is on data rather than procedure

 Objects, which are usually instances of classes, are used to interact with one another to design
applications and computer programs.
 Object-oriented programming takes the view that what we really care about the objects we want
to manipulate rather than the logic required to manipulate them.

 Example C++, Java, Python, Perl, C# etc.

4
Principles of Object Oriented Programming

Objects

01
Dynamic Binding Encapsulation

02
Classes OOP Data Abstraction
03

Inheritance
04 Polymorphism.

5
Cont…
Classes  Is the structure and behavior (data and code) that will be shared by a set of objects
 A class can be described as a blueprint that portrays the practices or expresses all the

behaviors and states of its objects..

Objects  Objects are instances of a class


 Object is the basic run-time entities in an object-oriented system
 Characteristics of an object are represented in a class as Properties (Data Members).
 Objects are characterized by two components such as methods & attributes or

variables.
Data Abstraction  Data abstraction is one of the most essential and important features of object oriented
programming
 Data Abstraction means displaying only essential information and hiding the details
 Data abstraction refers to providing only essential information about the data to the outside
world, hiding the background details or implementation. 6
Cont.…

Objects
Customer Class

Solomon
Wolkite
Name
Birr 1234
Address
Attributes or Data
Current Balance Chala
Addis Ababa
Birr 2500

Insert Address ()
Methods Foziya
Update Balance () Adama
Birr 1752
Delete Address ()

7
Encapsulation

Binding (or wrapping) code and data together into a single unit is known as encapsulation
Is a programming mechanism that binds together code and the data it manipulates, and that
keeps both safe from outside interference and misuse.
If a field is declared private, it cannot be accessed by anyone outside the class, thereby
hiding the fields within the class.
Encapsulation also lead to data abstraction or hiding. As using encapsulation also hides the
data.
Class is a program-code-template that allows developers to create an object that has both
variables (data) and behaviors (functions or methods).
8
Cont…

Encapsulation

9
Inheritance

 Inheritance is the process by which objects of one class can get the properties of objects of
another class.
 Inheritance means one class of objects inherits the data and behaviors from another class.
 Inheritance is the process of forming a new class from an existing class or base class
 The new class that is formed is called derived class. Derived class is also known as a child
class or sub class
 Inheritance helps in reducing the overall code size of the program, which is an important
concept in object-oriented programming

10
Cont..
Class: Academic
Name
Address

NoPeople()

Class: Teacher Class: Student

Salary Marks

getSalary() Average()

11
 Access modes can be classified into different categories:
 Public: When the member is declared as public, it is accessible to all the functions of the program.
 Private: When the member is declared as private, it is accessible within the class only.
 Protected: When the member is declared as protected, it is accessible within its own class as well as

the class immediately derived from it.

 Types of Inheritances:

12
Single inheritance: is defined as the inheritance in which a derived class is inherited from
the only one base class.
Multilevel inheritance is a process of deriving a class from another derived class
Multiple inheritance is the process of deriving a new class that inherits the attributes from
two or more classes.
Hierarchical inheritance is defined as the process of deriving more than one class from a
base class
Hybrid inheritance is a combination of more than one type of inheritance

13
Single Inheritance Multilevel Inheritance Multiple Inheritance

Hierarchical Inheritance Hybrid Inheritance

14
Benefits of Inheritance:

One of the key benefits of inheritance is to minimize the amount of duplicate code in
an application by sharing common code amongst several subclasses
Reusability - facility to use public methods of base class without rewriting the same.
Extensibility - extending the base class logic as per business logic of the derived class.
Data hiding - base class can decide to keep some data private so that it cannot be
altered by the derived class

15
Polymorphism

 Polymorphism is one of the OOPs feature that allows us to perform a single action in different
ways.
 As the word suggests, ‘poly’ means ‘many’ and ‘morph’ points at ‘forms’; thus,
polymorphism would mean ‘a property of having many forms
 It is the ability of an object to take many forms
 Inheritance lets users inherit attributes and methods, and polymorphism uses these methods to
perform different tasks
 In java, we use method overloading and method overriding to achieve polymorphism
 Is a feature that allows one interface to be used for a general class of actions
 Polymorphism plays a main role in allocate objects having different internal structures to share
the same external interface
16
Cont..
Shape
Calculate Area()

Rectangle Circle Square

Calculate Area() Calculate Area() Calculate Area()

17
Dynamic Binding

 Binding refers to the linking of a procedure call to the code to be executed in response to the call
 Dynamic binding means that the code related with a given procedure call is not known until the time of
the call at run time.
 Dynamic binding is associated polymorphism and inheritance.
 In the section above, on polymorphism, it was stated that 'at runtime, objects of the class Circle would
invoke the Calculate Area method from the Circle class while objects of the class Square would invoke
the Calculate Area method from the Square sub-class’.
 This idea is called dynamic binding or late binding. This means that the code associated with a given
procedure call is not known until the time of the call at runtime.
 For the Calculate Area method, the code that is executed depends on the class of the object for which it is
called
18
Introduction to Java
History of JAVA
 James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in
June 1991. The small team of Sun Engineers called “Green Team”.
 Originally designed for small, embedded systems in electronic appliances like set- top boxes.
 Firstly, it was called "Green talk" by James Gosling and file extension was “.gt”
 After that, it was called Oak and was developed as a part of the Green project.
 Finally, it come up with a name of Java with file extension “.java”
 Java is an Object-Oriented, Multi-threaded programming language
 Java enables users to develop and deploy applications on the internet for servers, desktop
computers, and small hand-held devices.

19
Features of Java

01 Object-Oriented 06 Multithreaded

02 Platform Independent 07 High performance

08 Dynamic
03 Robust

04 Distributed 09 Compiled and Interpreted

10
05 Simple Secure

20
Object- Oriented :

 Java is truly object-oriented language. In Java, almost everything is an object

 Object-oriented means we organize our software as a combination of different types of

objects that incorporate both data (Data Members) and behavior (Member Functions).

 All program code and data exist in objects and classes

 Java comes with an extensive set of classes; organize in packages that can be used in

program by inheritance.

 The object model in Java is trouble-free and easy to enlarge


21
Platform Independent:
 A platform is the hardware or software environment in which a program runs
 Java supports the feature portability.
 Java programs can be easily moved from one computer system to another and anywhere.
 Changes and upgrades in operating systems, processors and system resources will not
force any alteration in Java programs
 Java certifies portability in two ways
First way is, Java compiler generates the bytecode and that can be executed on any
machine.
Second way is, size of primitive data types are machine independent

22
Robustness
 Java is robust (strong) because.
It uses strong memory management
Java provides automatic garbage collection which runs on the Java Virtual Machine to get
rid of objects which are not being used by a Java application anymore
Java tries to kill circumstances, which can lead to potential system failures, by stressing
chiefly on runtime checking and compile time checking
Java encourages error-free programming by being strictly typed and performing run time
checks
Java also includes the concept of exception handling, which keeps serious errors and reduces
all kind of threat of crashing the system
23
Distributed

Java is distributed because it facilitates users to create distributed applications in Java.


This feature of Java makes us able to access files by calling the methods from any machine
on the internet
Java applications can open and access remote objects on internet easily. So, multiple
programmers at multiple remote locations to work together on single task
Java is designed for the distributed environment of the internet because it handles TCP/IP
protocols

24
Multithreaded :

A thread is like a separate program, executing concurrently


Java programs deals with many tasks at once by defining multiple threads
 Java was designed to meet the real-world requirement of creating interactive, networked
programs
 Java supports multithreaded programming, which allows you to write programs that do
many things simultaneously. Therefore, we need not wait for the application to complete
one task before starting next task.
 With Java’s multithreaded feature, it is conceivable to compose programs that can do
numerous assignments at the same time
25
High performance
Java is faster than other traditional interpreted programming languages because Java
bytecode is "close" to native code
Java performance is very extraordinary for an interpreted language, majorly due to the use
of Intermediate bytecode
The java bytecode is highly optimized for speed of execution With the utilization of Just-In-
Time compilers, Java enhances the performance of the system.
Java architecture is also designed to reduce overheads during runtime
It is still a little bit slower than a compiled language (e.g., C++). Java is an interpreted
language that is why it is slower than compiled languages, e.g., C, C++, etc.

26
Dynamic

Java is a dynamic language. It supports the dynamic loading of classes.


It means classes are loaded on demand
Java is capable of dynamically linking in new class, libraries, methods and objects.
Java projects can convey broad measure of run-time data that can be utilized to check for
accesses and respond to the same on run-time
Java supports dynamic compilation and automatic memory management (garbage
collection).

27
Compiled and Interpreted
 Java can be considered both a compiled and an interpreted language because its source code is first
compiled into a binary bytecode
 This byte-code runs on the Java Virtual Machine (JVM), which is usually a software-based
interpreter
 The Java interpreter converts the Java bytecode (.class file) into the code understand by the
operating system
 Java interpreter is a computer program (system software) that implements the JVM. It is responsible
for reading and executing the program.
 It is designed in such a way that it can read the source program and translate the source code
instruction by instruction. It converts the high-level program into assembly language (machine
language).
28
Secure
 Java is secured because Java Programs run inside a virtual machine sandbox
 Security is an important feature of Java and this is the strong reason that programmer use this language for
programming on internet
 With Java’s security framework, it empowers to create frameworks, which are free of viruses and tampering.
 Classloader in Java is a part of the Java Runtime Environment (JRE) which is used to load Java classes into
the Java Virtual Machine dynamically
 It adds security by separating the package for the classes of the local file system from those that are imported
from network sources

29
Simple
Java is very easy to learn, and its syntax is simple (based on C++), clean, and easy to
understand.
Java has removed many complicated and rarely used features, for example, explicit pointers,
operator overloading, etc.
There is no need to remove unreferenced objects because there is an Automatic Garbage
Collection in Java.
Java has a concise, cohesive set of features that makes it easy to learn and use
Assuming that you have some programming experience, you will not find Java hard to
master

30
Java Basic Terminology

31
Java Development Kit (JDK):
 It is a software development environment used for developing Java applications
 JDK is a kit (or package) that includes two things:
 Development Tools (provide an environment to develop your java programs)
 JRE (to execute your java program)
 JDK is the superset of the JRE and contains JRE with Java compiler, debugger, and core classes
 Uses JVM, interpreter/loader, a compiler, an archiver, a documentation generator (Javadoc), and
set of APIs to complete the development of Java application
 For the program to execute in java, we need to download and install JDK on our computer to
create, compile and run the java program

32
 Java Development kit (JDK) :It includes
Javac(It is a Java Compiler)
Java(It is a java interpreter)
Javap(Java disassembler, which convert byte code into program description)
Javah(It is for java C header files)
Javadoc(It is for creating HTML document)
Jdb(It is Java debugger)
Applet viewer( It is used for viewing the applet)

33
Java Runtime Environment (JRE):
It is an installation package that provides an environment to only run (not develop) the
java program (or application) onto your machine
JRE is a part of JDK which means that JDK includes JRE
It contains a set of libraries and other files that JVM uses at runtime.
JRE includes a browser, JVM, applet supports, and plugins.
For running the java program, a computer needs JRE

34
Java Virtual Machine (JVM):
 It is responsible for the program to execute line by line.

 It contains JIT (Just in Time Compiler), interpreter, and set of APIs.

 JIT optimizes bytecode to machine specific language compilation by


compiling similar bytecodes.
 JVM works to Load code, Verifies code, and Execute code and provides a
runtime environment.

35
The Byte Code
Bytecode in Java is an intermediate machine-independent code

The bytecode is not processed by the processor rather it is processed by the Java Virtual
Machine (JVM).
It is a set of instructions for Java Virtual Machine.

The job of the JVM is to call all the required resources to compile the Java program and
make the bytecode independent
It is the biggest reason why java is known as a platform-independent language

At runtime Java virtual machine takes bytecode(.class) as an input and convert this into
machine(windows, Linux, macOS etc.) specific code for further execution.
36
Working of Java Bytecode:
 JVM(Java Virtual Machine) acts as a run-time engine to run Java applications. Machine Code

05
.java file Javac .class file

01 Source Code
02 Compiler 03 Output Code 04 Virtual Machines

Create a source document. Use an The compiler creates a new


established protocol (in this case, Run your document through document, coded into Java The virtual machine reads
the Java language). a source code compiler bytecode
and runs the bytecode
.

37
Thank You!!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy