• No results found

BBIT 223/ CISY 210 Object Oriented Programming

N/A
N/A
Protected

Academic year: 2021

Share "BBIT 223/ CISY 210 Object Oriented Programming"

Copied!
22
0
0

Loading.... (view fulltext now)

Full text

(1)

BBIT 223/ CISY 210

Object Oriented Programming

Programming Paradigms: An

Overview

25.09.2012

Salesio M. Kiura

• Today

– Recap – Programming Paradigms – Exercises / Sample code

(2)

Recap

• From Last week

– Discussed course objectives

– Introduced the concept of Paradigms

(3)

• What is a paradigm:

– In science, paradigm describes distinct concepts or thought patterns in any scientific discipline or other epistemological context

• Programming Paradigm (wikipedia)

– A programming paradigm is a fundamental style of computer programming. There are four main paradigms : object-oriented, imperative,

functional and logic programming

A paradigm is not a language!

• Programming Paradigm

– programming “technique” (?) – way of thinking about programming – view of a program

• Programming Language

– consists of words, symbols, and rules for writing a program

(4)

Programming paradigms

• Imperative Programming

– program as a collection of statements and procedures affecting data (variables)

• Object-Oriented Programming

– program as a collection of classes for interacting objects

• Functional Programming

– program as a collection of (math) functions

Imperative Programming

• What Makes a Language Imperative?

– Programs written in imperative programming languages consist of

• A program state

• Instructions that change the program state

– Program instructions are “imperative” in the grammatical sense of imperative verbs that express a command

(5)

• Imperative verbs are also known as ‘bossy

verbs’- they tell people what to do! e.g. close

the door; empty the bin; eat your dinner!

• Commands in an imperative language are similar to the native machine instructions of traditional computer hardware – the von Neumann-Eckley model.

• Some old Imperative Languages – assembly languages

– 1954-1955: Fortran (FORmulaTRANslator) – Late 1950’s: Algol (ALGOrithmicLanguage)

(6)

Example

• What is it?

• What programming

features/aspects can

you identify?

• What has been the

successor?

• Defining Characteristics of Imperative

Languages:

– Statements are commands

• Command order is critical to correct execution; • Programmers control all aspects: algorithm

specification, memory management, variable declarations, etc

– They work by modifying program state

(7)

• Imperative: Summary

– Imperative programming is the oldest programming paradigm

– It is based on the von Neumann-Eckley model of a computer

– It works by changing the program state through assignment statements

– Procedural abstraction & structured programming are its design techniques.

Programming paradigms

• Imperative Programming

– program as a collection of statements and procedures affecting data (variables)

• Object-Oriented Programming

– program as a collection of classes for interacting objects

• Functional Programming

(8)

Functional Programming

• Functional programming is style of

programming in which the basic method of

computation is the application of functions to

arguments;

• A functional language is one that supports and

encourages the functional style.

• Example:

– The computation method is variable assignment

sum= 0;

for (int i = 1; i ≤ 10; ++i) total = total+i;

(9)

• In a functional language this would be

different:

– sum [1..10] Other examples: – Average [1..5] – Prod [2 5]

– The computation method is function application

•  functional programming is a programming

paradigm that treats computation as the

evaluation of mathematical functions and

avoids state and mutable data

(10)

Programming paradigms

• Imperative Programming

– program as a collection of statements and procedures affecting data (variables)

• Object-Oriented Programming

– program as a collection of classes for interacting objects

• Functional Programming

– program as a collection of (math) functions

• Logic programming

Logic Programming

• Based on Logic !

• Logic programming is based on the idea of

using logical sentences to represent programs

and to perform computation

• E.g.

(11)

• Example languages

– Prolog – LISP – Etc

• Application areas:

– Knowledge representation – Problem solving – etc

Paradigms: Summary

(12)

• Programming Paradigm

– A way of conceptualizing what it means to

perform computation and how tasks to be carried out on the computer should be structured and organized.

– Computation refers to Implementation of an I/O relation

•• Imperative programs

Imperative programs describe the details of

describe the details of

HOW

HOW the results are to be obtained, in terms

the results are to be obtained, in terms

of the underlying machine model.

of the underlying machine model.

• Functional/Logic programs specify WHAT is to

be computed abstractly, leaving the details of

data organization and instruction sequencing

to the interpreter.

(13)

Illustration Exercise

• Given the expression (to be computed) as:

a+b+c

• Which is imperative, which is functional?

1. 1.

• T := a + b; T := T + c;

2. 2.

• Load a; Add b; Add c

• Push a; Push b; Add; Push c; Add

Illustration Exercise

• Which is imperative, which is functional? –

answer:

1. Functional

• T := a + b; T := T + c; (Intermediate Code Intermediate Code )

2.

2. Impreative

Impreative

• Load a; Add b; Add c (Accumulator MachineAccumulator Machine) • Push a; Push b; Add; Push c; Add (Stack MachineStack Machine)

(14)

Paradigms - continued

• Object-Oriented Style

– Involves programming with Abstract Data Types

•• ADTs specify/describe behaviors.ADTs specify/describe behaviors.

– The basic program unit is a Class

•• Implementation of an ADT.Implementation of an ADT.

• Abstraction is enforced by encapsulation.

– The basic Run-time unit is an Object

•• Instance of a class.Instance of a class. • Has an associated state.

Procedural vs Object-Oriented

programming

• Procedural:

• Emphasis on procedural abstraction. • Top-down design; Step-wise refinement. • Suited for programming in the small.

• Object oriented

• Emphasis on data abstraction.

(15)

JAVA

• Is used for creating:

– intelligent consumer-electronic devices (cell phones)

– Web pages with dynamic content

(16)

Java life cycle

• Java programs normally undergo four phases:

• Edit (Source code (.java))

Programmer writes program (and stores program on disk) • Compile (Byte codes (.class) , as (.exe) in c++

Compiler creates bytecodes from program (.class as .exe in c++)

• Load

Class loader stores bytecodes in memory • Execute

Interpreter: translates bytecodes into machine language

• Other concepts

– The Java Application Programming Interface (API)

• a large collection of ready-made software components. It is grouped into libraries of related classes and interfaces; these libraries are known as packages.

• E.g. System.out.*; java.util.* – Java Virtual Machine (JVM)

(17)

Portability of Java

• Through the Java VM, the same application is

(18)

Java technology series

• Java EE vs. Java SE

– EE: enterprise edition (web services, distribution, RMI, …) – SE: standard edition (stand alone applications)

• Development Tools

– The main tools you'll be using are the javac compiler, the java launcher (java), and the javadoc documentation tool.

• Application Programming Interface (API)

– Java SE Development Kit 6 (JDK 6)

– Offers a wide array of useful classes ready for use in your own applications.

(19)

• User Interface Toolkits

– Swing and Java 2D toolkits to create Graphical User Interfaces (GUIs).

• Integration Libraries

– Application Programming Interface (API) – Java RMI (Remote Method Invocation) over

Internet and Inter-ORB (Object Request Broker) protocol technology enable database access

• Recap Part 2: Getting started with Java (Using

Jcreator)

• Exercise objective:

– Get started with Java and understand foundations of a Java program

(20)

Practice: Your own work

• Required

– Using jCreator, edit (create), compile (build)and run a simple java application that displays “Hello World”

– 20 Mins (because of the typing involved)

setting up JCreator?

public class HelloWorld

{

//main method

public static void main (String args [])

{

System.out.println("Hello World!");

}

(21)

• In the Java programming language, every

application must contain a main method whose

signature is:

• public static void main(String[] args)

– The modifiers public and static can be written in either order (public static or static public).

– You can name the argument anything you want, but most programmers choose "args" or "argv.“

– This is the string array that will contains the command line arguments.

• The main method is the entry point for your application and will subsequently invoke all the other methods required by your program.

• System.out.println("Hello World!");

– uses the System class from the API to print the "Hello World!" message to standard output.

(22)

Exercise

• Due next week

– Form groups of at least 3 or 4 members

– Formally describe the programming Ideas that were discussed last week

– Post the results as comments in the class blog

http://oop2012sept.wordpress.com/as a comment (use the “leave a reply” link)

– Write a program that stores two integers (e.g. x = 3, y = 2). Then in the program, you should interchange the values such that the value in x is stored in y and vice versa

References

Related documents

The use of the emergency released vapor (0.2MPa/120ºC) can generate an emergency 2Mwe.. The production cost of the nuclear electricity. In calculating the reduced costs of production

In a significant number of cases, it was evident that drug and/or alcohol abuse by parents was having a very damaging effect on their ability to consistently parent their

In the current study, we examined the effect of oral administration of CNN on severity of colitis, inflammatory state in the colon, colonic histology, goblet cell number,

(1) Flying evaluation board action is manda- tory for each Army aviator who requests or who is recommended for indefinite suspension from flying status, except in the case of an

Longitudinal collection of electronic health information for and about persons, where health information is defined as information pertaining to the health of an

The sea generated inside the estuary was affected by the tidal currents and modulations on the wave energy, wave periods, and directions were identified.. Summary

Sama seperti lapisan masyarakat di Desa Beringin Agung, dapat disimpulkan bahwa masing-masing rumahtangga petani di Desa Pendahara cenderung memilih mencari ikan di sungai sebagai