40
1 Course Focus 1. Programming (any language) PP (Procedural Programming) OOP (Object-Oriented Programming) 2. Problem solving Understand the problem & requirements (I P O S) Design modular program structure Design algorithms Code Test & Debug 3. Java language (the basics) 4. IDE: NetBeans (the basics)

1 Course Focus 1.Programming (any language) PP (Procedural Programming) OOP (Object-Oriented Programming) 2.Problem solving Understand the problem & requirements

Embed Size (px)

Citation preview

1

Course Focus

1. Programming (any language)

PP (Procedural Programming) OOP (Object-Oriented Programming)

2. Problem solving Understand the problem & requirements (I P O S) Design modular program structure Design algorithms Code Test & Debug

3. Java language (the basics)

4. IDE: NetBeans (the basics)

2

What’s “a computer”?Laptop, desktop

Mainframe, supercomputer

Tablet, smart phone, Tivo, Xbox, …

Server: print server, file server, DB server, web server, …

3

2 parts of a computerHardware (HW)

1. CPU2. Memory (RAM, …)3. Storage: Disk, CD, DVD, thumb drive, SD card,…4. I/O devices 5. Connectivity: network, wifi, bluetooth, ethernet,…

Software (SW) programs makes the computer “smart” controls HW hides most HW from user

4

HW – CPU

1) CU (Control Unit) - Boss fetch & decode instruction

(the one specified in PC (program

counter) ) call & pass data to/from other HW units

2) ALU (Arithmetic & Logic Unit) - Worker arithmetic + - * / comparisons == != < > <= >=

1-5

IPO (Input/Processing/Output)

Instruction (input) Result (output)

ArithmeticLogicUnit

ControlUnit

CPU

6

HW – Storage

1 - Primary storage = Memory (RAM) internal storage temporary, volatile, small, fast-access e.g., 512MB . . . 4GB, . . .

2 - Secondary storage disk, CD, DVD, SD card, thumb drive external storage permanent, large capacity, slow-access e.g., 500GB, . . . 1TB, . . . HD

(or 8GB flash drive in netbook) . . .

7

HW – Storage - RAM “Random Access Memory” contains

Currently running PROGRAMS DATA used by those programs

RAM divided into bytes,grouped into words Each word has a unique address

8

bits & bytes & words A byte = 8 bits

a bit is either ON (1) or OFF (0) A word = 4 bytes (32-bit system)

= 8 bytes (64-bit system) Bytes/words contain:

Machine language instruction Data:

1 char (‘A’) stored in 1 byte 1 integer (2763101) stored in 4 bytes

9

HW – I/OInput:

keyboard, mouse, touchscreen, . . .camera, scanner, microphone,

. . . file, DB, internet, . . .

Output: screen, printer, AV device, . . . controller for machine / robot, . . . file, DB, internet, . . .

10

SW (programs)

system SW OS, utilities, device drivers, compilers,

text editors, network SW, . . .

application SW general-purpose

DBMS, MS Office, browser application-specific

Payroll, WMU registration

11

Programmer Application programmer Systems “ Database “ Network “ Web “ . . . . . . Games, AI, graphics, . . . programmer

12

Program recipe detailed step-by-step

set of INSTRUCTIONS tells computer EXACTLY what to do controls HW processes data an algorithm to solve a problem

implemented in a programming language

1-13

Algorithm

set of well-defined steps to complete a specific task steps performed sequentially (unless…)

algorithm translated to machine language algorithm written in

pseudocode or flowchart or . . . developer implements algorithm in a

high-level language (like Java) compiler produces machine language

(all 0’s and 1’s)

14

Software EngineerProgrammer - “Developer”Systems Analyst - “Designer”

SW Engineering activities: Plan, design, test, document Code (= write program) Develop GUI Develop modules (classes) Customize package Build SW from components . . .

15

IPO model (IPSO model)

Input Processing Output & Storing

16

IPO (IPSO) modelHUMAN

see/hear [think & remember] speak/write

HW mouse/KB … [CPU & RAM & disk] screen, …

SW (traditional program)

data [process & store] data(user/file/DB) (user/file/DB)

^^^^^^^^^^ [= the PROGRAM]

17

Data text, numbers

graphics, sound, images, movies, . . .

mouse clicks (single/double, left/right), mouse hovers, . . .

web page, text message, . . .

18

Types of applications Batch processing

Typically: file in, file/printer out Interactive

simple text I/O with user (Console App)

GUI (Windows App)(Web App)

Java can do all of theseCS1110 – mainly Console Applications

19

IPSO - SWwindows application

user input [process & store] screen display mouse clicks DB data in a form

a SW module (a method)

input parameter [procedure] return value [& local variables]

[& class’s instance variables]

20

Types of Programs/Programming

Event-driven program Modular program Visual program Structured program Procedural program (next time & …)

Object-oriented program (couple weeks) OOP

Java can do all of these

21

Event-driven programmingIPO: event [handler module

in program] effectsEvents:

left-mouse-click on button/slider bar/menu item, mouse hovers over X,user hits Enter key, hit F5 key,sensor detects change,change made to the DB,. . .

Programming: write a module to handleANY event that could happen

22

Windows App vs. Console App

Event-driven Windows app Console app

Input: PUSHed into program program by user

PULLed into program by program

Controller: user program (main)

Interface: windows/GUI/visual/web/. . .

console (text)

Mode: interactive batch orsimple text I/O

23

Modular programming

Program = a collection of small modulesA module is:

(in Procedural Programming) an IPSO procedure or function

(in Object Oriented Programming) a Class (object) a IPSO method within a class

~ procedure

Programming – write modules Top-down or bottom-up

24

Visual Programming

Visual C#, Visual Basic, Java with library of classes

1) Construct GUI from pre-existing components Text box, radio button, slider bar, dropdown list,...

2) Adjust properties of these objects3) Add procedural code (a module) specifying:

WHAT to do for

each EVENT that might happen to this object(Much code is automatically generated for an object)

25

Structured ProgrammingAll procedural code (Java methods) is made from stacking or

nesting of:

1) Sequence Structureaction1, action2,

action3, . . .

2) Selection (condition) Structureif conditionX is true

then action1else

action2

3) Repetition (loop) Structurewhile conditionX is

true do{ action1,

action2,...

}

Procedural Programming (PP) Older languages were procedural A procedure = a set of language

statements which do a specific task Program is mainly a set of procedures Procedures

operate on program’s data typically operate on data items separate

from procedure itself data commonly passed from one procedure

to another

1-27

PP

Data tends to be global (available) to entire program & all procedures data being passed to/from (between)

procedures

DISADVANTAGE:If data formats changethen procedures that operate on

that data must be changed

1-28

Object-Oriented Programming (OOP)

OOP focus: create objects(vs. procedures)

Objects are combo of1. Data – the attributes of the object2. Procedures that manipulate that data

- methods(behaviors, local procedures,

services)

1-29

OOP Encapsulation - combine data & behavior

Data hiding = object X’s data not visible to other objects in program

Only object X’s methods can directly manipulate object X’s data Other objects can only access/manipulate

object X’s attributes via object X’s methods

30

Programming

= problem-solving solution

1) Solve the problem right AND2) Solve the right problem

Determine:WHAT needs to be doneHOW to do it (the algorithm)

31

Example Problems iPhone app List Song titles in alpha order on iPod Calculate final grade in CS1110 Candy Pay off a car loan at X% over Y years Google Maps

– find shortest route KZoo NY

32

Steps in programming

1. Requirements specification (what) input, processing, output

2. Program design (how) algorithm, modules, GUI

3. Coding (development) [in Java]4. Testing & debugging

compilation & logic & runtime errors validate results

5. Documentation (external)6. Maintenance

33

Algorithm (the “P” of IPSO)EXAMPLE: find sum of 1st 100 integers

User’s view: BLACK-boxProgrammer’s view WHITE(“clear”)-box

(write & test actual code)

Program’s processing could: Look it up in a table / file / DB Crowdsource the microtask on the web Calculate it using Algorthm1 or Algorithm2 or ...

34

Construct program from

pre-existing classes/methods in library just need to know interface (I/O)

classes/methods written by programmer

35

Basic Operations (processing)used in a program

1) Actual Work arithmetic comparison ( =, <, >, and, or, not)

2) Move/store data Assignment Mem Mem I/O (Read)

KB/mouse/text-on-screen/touchscreen/file/… Mem

I/O (Write)Mem screen/printer/file/…

36

3) Control the flow(what instruction executes

next) default: do next line maybe do this line (if, switch) jump to specific line (loop, break) goto & return (call)

4) Packaging Methods (procedures) Classes

37

1st & 2nd Generation Programming Languages

Machine Languages (ML) 11010010001010011110000111000111 1940’s programmers wrote in ML Machine-dependent

- each CPU has its own ML (Mac vs. PC)

Assembly Languages Add 210(8,13) Machine-dependent

38

3rd Generation Languages

High Level Languages (HLL) Java, C, C#, C++, Python, Ruby, PHP,

Visual BASIC, COBOL, Javascript Not processor-dependent

average = (ex1 + ex2 + ex3) / 3;

39

3rd Generation Languages

2 main programming paradigms Procedural (PP)

C, COBOL, Fortran, Basic, ... , any OOP language can do PP

Object-oriented (OOP) Java, C#, C++, Visual Basic Revised versions of COBOL

40

4th & 5th Generation Languages

Application-specific Languagese.g., SQL for DBS

Select name, phone from studentwhere major = “CS” and state = “MI”;

Natural Languages (English, . . .)If patient is age 65 or older

and is disorientedand has pain in his/her left arm

then patient could have had a heart attack