1. Chapter 1 – Introduction to Java and OOP
Concepts
By
Sirage Zeynu (M.Tech)
Computing Science
Debre Berhan University
2. 13-04-2021 Introduction to Java and OO Concepts 2
Computer is a device that performs tasks based on given set of step-
by-step instructions (procedures)
These set of procedures (step-by-step instructions) are called
algorithms also called computer programs or software's.
Computing is a constantly changing our world and our environment.
The way in which we tell/give the set of procedures or programs to a computer are
called programming languages. Examples are: C++, java, C#...
In order to write a program you need to go through several stages. These are
1. Type the text of the program into the computer
2. Translate the program text into a form the computer can use
3. Run the translated program
Basics of programming
3. 13-04-2021 Introduction to Java and OO Concepts 3
There are different types of programming languages based on the
philosophy they use.
Procedural Programming:
is a programming paradigm/modelling approach in which a list of step-
by-step instructions telling a computer, what to do one after the other
linear order of execution from the first statement to the end.
Example C, FORTRAN, Pascal, and Basic.
The procedural-oriented programs are made up of functions. Functions
are less reusable
It is very difficult to copy a function from one program and reuse in
another program because the function is likely to reference the global
variables and other functions.
The procedural languages are not suitable of high-level abstraction for
solving real life problems.
Programming paradigms
4. 13-04-2021 Introduction to Java and OO Concepts 4
Object oriented programming(OOP):
is a programming paradigm/modelling approach that
represents concepts as "objects" that have
◦ data fields (attributes that describe the object) and
◦ Associated procedures known as methods/functions that
operate or manage the data.
◦ OOP languages permit higher level of abstraction for
solving real-life problems.
◦ The basic unit of OOP is a class, which encapsulates both
the static properties and dynamic operations
Examples : C++, Java, PHP, C#...
Programming paradigms
5. 13-04-2021 Introduction to Java and OO Concepts 5
Java programming language was originally developed by
Sun Microsystems which was initiated by James Gosling and
released in 1995 as core component of Sun Microsystems' Java
platform (Java 1.0 [J2SE]).
The latest release of the Java Standard Edition is Java SE 11.
With the advancement of Java and its widespread popularity,
multiple configurations were built to suit various types of
platforms.
For example: J2EE for Enterprise Applications, J2ME for Mobile
Applications.
The new J2 versions were renamed as Java SE, Java EE, and Java
ME respectively.
Java is guaranteed to be Write Once, Run Anywhere.
Java Overview
6. 13-04-2021 Introduction to Java and OO Concepts 6
Object Oriented: In Java, everything is an Object. Java can be
easily extended since it is based on the Object model.
Simple: Java is designed to be easy to learn. If you understand
the basic concept of OOP, Java would be easy to master.
Secure: With Java's secure feature, it enables to develop virus-
free, tamper-free systems. Authentication techniques are based
on public-key encryption
Architectural-neutral: Java compiler generates an
architecture-neutral object file format, which makes the
compiled code to be executable on many processors, with the
presence of Java runtime system
Features of Java programming language
7. 13-04-2021 Introduction to Java and OO Concepts 7
Robust: Java makes an effort to eliminate error prone situations by
emphasizing mainly on compile time error checking and runtime
checking.
Multithreaded: With Java's multithreaded feature, it is possible to write
programs that can do many tasks simultaneously. This design feature
allows developers to construct smoothly running interactive
applications.
High Performance: With the use of Just-In-Time compilers, Java
enables high performance.
Dynamic: Java is considered to be more dynamic than C or C++ since it
is designed to adapt to an evolving environment.
Features of Java programming language
8. 13-04-2021 Introduction to Java and OO Concepts 8
Distributed: Java is designed for the distributed environment of the internet.
Compiled and interpreted: java is both compiled and interpreted.
The Java compiler translates the program into an intermediate language called Java
byte-codes.
Java byte-codes are platform-independent – this means they can be run on different
operating systems (e.g. Windows, Linux, Mac...). There are different Java interpreters
for different platforms. These interpreters parse and run each of the Java byte-code
instructions to each machine code in which the machine can understand. The
interpreters are usually called java Virtual Machine.
It is called a Virtual Machine because it is like a computer that does not physically exist
the JVM exists only within the memory of the computer. The Java byte-codes are like a
set of machine code instructions for the JVM.
Compilation only needs to happen one time, whereas interpretation happens every time
the program is executed
Features of Java programming language
9. 13-04-2021 Introduction to Java and OO Concepts 9
Java environment includes a large number of development tools and
hundreds of classes & methods.
You can download the most up-to-date JDK and its documentation from
java.sun.com/
The development tools are part of the system known as java development
kit (JDK).
The set of classes and methods are part of the Java Standard Library(API),
also known as Application Programming Interface(API).
JAVA development Environment
10. 13-04-2021 Introduction to Java and OO Concepts 10
Comes with a collection of tools that are used for developing and
running java programs. They include
◦ javac --- java compiler
◦ java --- java interpreter
◦ jdb --- java debugger etc...
So, to develop java programs, we need to install jdk. And then we can
use our own text editor to write java source code. Or instead of using our
own text editor, another option we can use is installing other tools or
APIs like Net-beans and Eclipse to easily code, compile and run java
programs.
Java Development Kit (JDK)
11. 13-04-2021 Introduction to Java and OO Concepts 11
The Java API consists of many built-in classes and methods that we can
use in our code. These classes and methods/functions are again grouped
into a form packages. Package is a collection of related classes together.
Some of the most commonly used packages are the following:
Language support package (java.lang) – classes required for
implementing basic features of Java.
Utilities package (java.util) – classes that provide various utility functions
such as date and time functions.
Input/Output package (java.io) – classes required for manipulation of input/output
to/from programs
Networking Package (java.net) – classes used for communicating with other
programs/PCs over networks and internet
Applet Package (java.applet) – classes that are used to create Java applets.
Main Java API packages include:
12. 13-04-2021 Introduction to Java and OO Concepts 12
Java programs normally go through five phases—edit, compile, load, verify and exe- cute.
14. 13-04-2021 Introduction to Java and OO Concepts 14
Objects
classes
Data abstraction
encapsulation
Inheritance
Polymorphism
Dynamic (late) binding
Message communication
The basic concepts of OO are
15. 13-04-2021 Introduction to Java and OO Concepts 15
classes
A ‘class’ is a software design which describes the general properties of
something which the software is modelling.
A class is the definition of a set of objects or a class is the design of an
object. A class models a static view of objects which exist in the system
users' world.
A class can be visualized as a three-compartment box, as illustrated:
Name (or identity): identifies the class.
Variables (or attribute, state, field): contains the static attributes of the
class.
Methods (or behaviours, function, operation): contains the dynamic
behaviors of the class.
The basic concepts of OOP
16. 13-04-2021 Introduction to Java and OO Concepts 16
Objects
Individual ‘objects’ are created from the class design for each
actual thing.
Objects are the basic runtime entities in an OO program.
An object are an identifiable thing or individual containing
The term "object" usually refers to instance. But it is often
used loosely, and may refer to a class or an instance
The basic concepts of OOP
17. 13-04-2021 Introduction to Java and OO Concepts 17
Encapsulation:
means the wrapping up of data and methods into a single unit (a class). It also means
that the data inside a class is hidden from everything outside the class.
The data can only be accessed by invoking the methods of the class. The internal
workings of the methods are of no concern to other classes in the program.
Abstraction:
refers to the way in which a class represents only the essential features of the set of
objects it models – a class does not include background or extra details that are not
relevant to the system.
So a class is like a list of abstract attributes e.g. size, weight, cost, and the methods that
operate on those attributes e.g. change the cost, increase the weight.
The basic concepts of OOP
18. 13-04-2021 Introduction to Java and OO Concepts 18
Inheritance
Inheritance is the way in which objects of one class get the properties of
objects of another class. This includes the data/ attributes and the methods.
Polymorphism
The word polymorphism means the ability to take more than one
form/structure. A particular operation/method may behave differently for
different number of inputs.
polymorphism (literally "multiple-forms").
Polymorphism is often called late- binding because the receiver object
binds the message to an appropriate implementation function (method in
Java terminology) at run-time when the message is sent rather than at
compile-time as functions are.
The basic concepts of OOP
19. 13-04-2021 Introduction to Java and OO Concepts 19
Reuse of existing classes and eliminate redundant code using inheritance.
Encapsulation (hiding of data) helps with the building of more secure
programs
There is a close link between objects in the real-world system and objects in
the program. Therefore, the structure of the system is more likely to be
meaningful to users.
The work for a given project can be divided by class/object – making it easier
to split work up between a team of developers.
OO systems can be easily upgraded from small to larger systems.
The message passing technique for communication between objects makes it
easy to describe the interface of an OO system for other systems that need to
communicate with it.
Software complexity can be easily managed....
isolation of programmers (better team programming)
The Benefits of OOP