0% found this document useful (0 votes)
33 views

CPE207 Object Oriented Programming (Week 1)

Uploaded by

mertbalaban58
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)
33 views

CPE207 Object Oriented Programming (Week 1)

Uploaded by

mertbalaban58
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/ 31

Week 1

Object-Oriented Programming
(in Java)

Dr. Nehad Ramaha,


Computer Engineering Department
Karabük Universities 1
The class notes are a compilation and edition from many sources. The instructor does not claim intellectual property or ownership of the lecture notes.
Week1 : Introduction to Object-Oriented Programming
L1, L2 Week2 : Introduction to Classes: Declaring a class and initializing an object
Week3: Introduction to Classes: Class Constructors, UML
L3, L4
Week4 : OOP in Java: OOP Concepts: Encapsulation + (Exception handling).
Week5 : OOP in Java : Static methods, Nested Classes, Enum types, Deeper in
L5, L6 classes
Week6 :Deeper in Classes: this() method & toString() + Examples
Week7 : Deeper in Classes: Working with multiple classes
L7, L8
Week8 :OOP Concepts: Inheritance
Week9 : OOP Concepts: Polymorphism
L9, L10
Week10: OOP Concepts: Abstraction => Interfaces, Multiple inheritance
Week11:Java Collections Framework: Lists
L11, L12
Week12: Java Collections Framework: Set & Map
Week13: GUI using NetBeans
L13, L14
Week14: GUI-2
2
 Precaution
 Installing IDE for Java
 Computer Languages
 Fundamental concepts:
◦ Classes
◦ Objects
◦ Instance
◦ OOP concepts

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

 If you do not have Java installed on your


computer, you can download it for free at
oracle.com.

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)

 Or simply Google it!

 Choose Windows x64 and


install

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).

public class Main {


public static void main(String[] args) {
System.out.println("Hello World");
}
}

Save the code in Notepad as "Main.java".

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

The JVM takes the byte code and generates


machine code.

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).

 Object-oriented design approach is much more


productive than with earlier popular techniques
like “structured programming”
 Object-oriented programs are often easier to
understand, correct and modify.
24
 Class − A class is a blueprint or
template or set of instructions to
build a specific type of object

 Object- An object is a component


that contains attributes and
behaviors needed to make a
certain type of data useful.

 Instance- An instance is a specific


object built from a specific class

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.

public class Dog {


String breed;
variables

int age;
String color; attributes public class JavaApplication1 {

public static void main(String[] args)


{
void bark() {}
methods

Dog dog = new Dog();


void hunger() {}
void sleep() {} behaviors dog.bark();
}
} }

Object: An instance of Dog class Method call

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

You might also like