CPE207 Object Oriented Programming (Week 1)
CPE207 Object Oriented Programming (Week 1)
Object-Oriented Programming
(in Java)
CPE207 OOP 3
1. Attendance:
◦ 5 times absence will prevent you to take final and makeup
exam.
2. Evaluation:
◦ Midterm %40, Final exam %50, Project +%10
CPE207 OOP 4
This course enables the students to know about
1. Classes & Objects
2. Object Oriented concepts, Java language
◦ Inheritance,
◦ Polymorphism,
◦ Abstraction,
◦ Encapsulation
CPE207 OOP 5
Computers understand only Machine Language
6
7
The fundamental language of the computer’s
processor, also called Low Level Language.
All programs are converted into machine
language before they can be executed.
Consists of combination of 0’s and 1’s that
represent high and low electrical voltage.
8
A low level language that is similar to machine
language.
Uses symbolic operation code to represent the
machine operation code.
9
Computer (programming) languages that are easier to
learn.
Uses English like statements.
there are hundreds of high level programming
languages, following are a few of them:
Java
C
C++
Python
PHP
Perl
Ruby
10
You eventually need to convert your program
into machine language so that the computer
can understand it.
There are two ways to do this:
Compile the program.
Interpret the program.
11
Compile is to transform a program written in
a high-level programming language from
source code into object code.
This can be done by using a tool called
compiler.
A compiler reads the whole source code and
translates it into a complete machine code
program to perform the required tasks which
is output as a new file.
12
Interpreter is a program that executes
instructions written in a high-level language.
An interpreter reads the source code one
instruction or line at a time, converts this line
into machine code and executes it.
13
Java is a popular programming language, created in
1995.
It is owned by Oracle, and more than 3 billion devices
run Java.
It is used for:
◦ Mobile applications (specially Android apps)
◦ Desktop applications
◦ Web applications
◦ Web servers and application servers
◦ Games
◦ Database connection
◦ And much, much more!
14
Java works on different platforms (Windows, Mac, Linux,
Raspberry Pi, etc.)
It is one of the most popular programming language in the world
It is easy to learn and simple to use
It is open-source and free
It is secure, fast and powerful
It has a huge community support (tens of millions of developers)
Java is an object oriented language which gives a clear structure
to programs and allows code to be reused, lowering
development costs
As Java is close to C++ and C#, it makes it easy for programmers
to switch to Java or vice versa
15
To check if you have Java installed on a Windows
PC, search in the start bar for Java or type the
following in Command Prompt (cmd.exe):
◦ java -version
16
Install JDK 8u111 with
NetBeans 8.2
◦ Use the following link
(https://www.oracle.com/te
chnetwork/java/javase/dow
nloads/jdk-netbeans-jsp-
3413139-esa.html)
17
In Java, every application begins with a class name, and that class must
match the filename.
Let's create our first Java file, called Main.java, which can be done in any
text editor (like Notepad).
18
Open Command Prompt
(cmd.exe), navigate to the
directory where you saved your
file, and type:
◦ javac Main.java
This will compile your code. If
there are no errors in the code,
the command prompt will take
you to the next line. Now, to
run the file type:
◦ java Main
19
Java Standard Edition (SE) contains the capabilities needed
to develop desktop and server applications.
The Java Enterprise Edition (Java EE) is geared toward
developing large-scale, distributed networking
applications and web-based applications.
Java Micro Edition (Java ME) a subset of Java SE. geared
toward developing applications for resource-constrained
embedded devices, such as:
◦ Smart watches
◦ MP3 players
◦ television set-top boxes
◦ smart meters (for monitoring electric energy usage)
◦ and more.
20
Need for OOP
21
POP OOP
Main focus is on "how Main focus is on 'data
to get the task done" security'. Hence, only
i.e. on the procedure
or structure of a objects are permitted to
program access the entities of a
Large program is class.
divided into Entire program is divided
functions(methods) into objects.
C, VB, FORTRAN, C++, JAVA, C#,
Pascal Objective-C, phyton
22
function = method
POP OOP
23
Objects (comes from classes) are reusable.
◦ Date, time, audio, video, automobile, people objects,
etc.
◦ Almost any noun can be represented as an object in
terms of
attributes (e.g., name, color and size) and
behaviors (e.g., calculating, moving and communicating).
25
Objects have
attributes (e.g., name, color and size) and (variables)
behaviors (e.g., calculating, moving and communicating). (methods)
A car has attributes
◦ Color, its number of doors, the amount of gas in its tank, its
current speed and its record of total miles driven (i.e., its
odometer reading).
◦ The car’s attributes are represented as part of its design in
its engineering diagrams.
Every car maintains its own attributes.
methods are used to perform some tasks of the
objects.
CME225 OOP 26
Just as someone has to build a car from its
engineering drawings before you can actually
drive a car, you must build an object of a
class before a program can perform the tasks
that the class’s methods define.
An object is then referred to as an instance of
its class.
CME225 OOP 27
A class is a blueprint from which individual objects are created.
int age;
String color; attributes public class JavaApplication1 {
CME225 OOP 28
Another Example: Car class Behaviours
Attributes
StartEngine
Model
Color Drive
Year Stop
Price
This Car class can be reused many times to build many cars, you can reuse a class
many times to build many objects.
Reuse of existing classes when building new classes and programs saves time and
effort.
CME225 OOP 29
https://sites.google.com/view/oopinjava
CME225 OOP 30
31