Assosa University: College of Computing and Informatics
Assosa University: College of Computing and Informatics
1
Object-Oriented
Programming
Computer Science Year II
Compiled by: Gebreigziabher A.
2
Introduction to Object Oriented
Programming
3
•Java was conceived by James Gosling, Patrick
Naughton, Chris Warth, Ed Frank, and Mike
Sheridan at Sun Microsystems in 1991. This
language was initially called “Oak” which was
designed for the development of software for
consumer electronic devices, but was renamed
“Java” in 1995.
•Java evolved from C++, which evolved from C,
which evolved from BCPL and B.
• Java is directly related to both C and C++. Java inherits
its syntax from C. Its object model
4 is adapted from C++.
• Originally Java was not designed for developing
Internet-based applications rather the need for a
platform-independent language used to create
software to be embedded in various consumer
electronic devices(microwave ovens, remote controls).
• Java has become now the language of choice for
implementing Internet-based applications and software
for devices that communicate over a network.
• Java Enterprise Edition (Java EE) is geared toward
developing large-scale, distributed networking
applications and web-based 5applications.
• Java Micro Edition (Java ME) is geared toward
developing applications for small, memory-constrained
devices, such as cell phones, pagers and PDAs..
• Java is used to develop large-scale enterprise
applications, to enhance the functionality of web
servers, to provide applications for consumer devices.
• Java programs consist of pieces called classes. Classes
include pieces called methods that perform tasks and
return information when the tasks are completed.
6
Programming languages are divided into three
general types:
1. Machine language
2. Assembly language
3. High-level language
7
2. Assembly Languages: Uses symbolic
instructions and executable machine codes called
mnemonics to write programs.
E.g. To add any two numbers A and B
ADD A, B – Adds two numbers in memory location A and B
•A translator that converts Assembly language in
to Machine code is called Assembler.
8
3. High-level Languages : Uses English like
statements to write programs.
E.g. To add any two numbers A and B
sum = A + B
•A translator that converts High level
language in to Machine code is called
Compiler.
[FORTRAN, BASIC,C++,Java]
9
• OBJECT-ORIENTATION is a set of tools and methods
that enable software engineers to build reliable, user
friendly, maintainable, well documented, reusable
software systems that fulfils the requirements of its
users.
• An object-oriented programming language provides
support for the following object oriented concepts:
1. Objects and Classes
2. Inheritance
3. Polymorphism and Dynamic binding
10
•To support the principles of object-oriented
programming, all OOP languages, including Java,
have three traits in common: encapsulation,
polymorphism, and inheritance.
1. Encapsulation
•Encapsulation is a programming mechanism that
binds together code and the data it manipulates,
and that keeps both safe from outside
interference and misuse.
11
2. Polymorphism [Take many forms]
•Polymorphism is the quality that allows one interface to
access a general class of actions.
•It is a feature of object-oriented languages whereby the
same method call can lead to different behaviors depending
on the type of object on which the method call is made.
•It’s the ability to create variables and methods that has more
than one form.
3. Inheritance
•Inheritance is the process by which one object can acquire
the properties of another object.
•It is the mechanism whereby a class acquires (inherits) the
methods and variables of its super classes.
12
•Simple: Java has a concise, cohesive set of
features that makes it easy to learn and
use.
•Secure: Java provides a secure means of
creating Internet applications. [Viruses]
•Portable: Java programs can execute in any
environment for which there is a Java run-
time system. [Used for developing internet -
based applications]
13
•Robust: Java encourages error-free
programming by being strictly typed and
performing run-time checks. [ Avoid crashes
during program execution]
• Multithreaded: Java provides integrated support for
multithreaded programming(Perform concurrent
computations).
•Architecture-neutral: Java is not tied to a specific
machine or operating system architecture
(Platform independent).
14
•Object-Oriented: Java is pure OOP language
-More efficient code reusability & code
maintainability.
•High performance: The Java bytecode is
highly optimized for speed of execution.
•Distributed: Java was designed with the
distributed environment of the Internet
(Handles TCP/IP protocols).
15
•An application is a program that runs on your
computer, under the operating system of that
computer.
•An applet is an application designed to be
transmitted over the Internet and executed by a
Java-compatible Web browser.
•What makes Java different from other computer
languages is its ability to create applets.
16
•Objects are instances of a class.
•An object is a software bundle of related
state and behaviour. Software objects are
used to model the real-world objects that
you find in everyday life.
•Objects interact with each other by passing
messages.
17
•A Class is a blueprint that defines the states
and the behaviors common to all objects of
a certain kind.
•A class is a collection of data and methods
that operate on that data.
•A method is the object-oriented term for a
procedure or a function.
18
•An interface is a contract between a class
and the outside world.
•A package is a namespace for organizing
classes and interfaces in a logical manner.
Placing your code into packages makes
large software projects easier to manage.
19
20
21
• Source Code Editors, IDEs (NetBeans, Eclipse,
Jbuilder, JCreater, BlueJ...)
• Java Virtual Machine (JVM):-Bytecode Interpreter.
• A virtual machine(VM) is a software application that
simulates a computer, but hides the underlying operating
system and hardware from the programs that interact with
the VM. If the same VM is implemented on many computer
platforms, applications that it executes can be used on all
those platforms. The JVM is one of the most widely used
virtual machines.
• The JVM is invoked by the java command java
progname 22
•Bytecode is a highly optimized set of
instructions designed to be executed by
the Java run-time system, which is called
the Java Virtual Machine (JVM).
•That is, in its standard form, the Java
Virtual Machine is an interpreter for
bytecode.
23
24