Computer Programming and Database Handout

61
MIS 315 - Bsharah Computer Programming and Database Handout Computer Programming and Database Handout

description

Computer Programming and Database Handout. Contents. Section A: Programming Basics Section B: Procedural Programming Section C: Object-Oriented Programming Section D: Declarative Programming Section E: Secure Programming Section F: Database Programming . Section A: Programming Basics. - PowerPoint PPT Presentation

Transcript of Computer Programming and Database Handout

Page 1: Computer Programming and Database Handout

MIS 315 - Bsharah

Computer Programming and Database Handout

Computer Programming and Database Handout

Page 2: Computer Programming and Database Handout

MIS 315 - Bsharah

2

Contents

• Section A: Programming Basics• Section B: Procedural Programming• Section C: Object-Oriented Programming• Section D: Declarative Programming• Section E: Secure Programming• Section F: Database Programming

Computer Programming and Database Handout

Page 3: Computer Programming and Database Handout

MIS 315 - Bsharah

3

Section A: Programming Basics

• Computer Programming and Software Engineering• Programming Languages and Paradigms• Program Planning• Program Coding • Programming Tools• Program Testing and Documentation

Computer Programming and Database Handout

Page 4: Computer Programming and Database Handout

MIS 315 - Bsharah

4

Computer Programming and Software Engineering• The instructions that make up a computer program are

often referred to as code.• Programs can have millions of lines of code.

– Developed by computer programmers• Computer programming

Computer Programming and Database Handout

Page 5: Computer Programming and Database Handout

MIS 315 - Bsharah

5

Computer Programming and Software Engineering

Computer Programming and Database Handout

Page 6: Computer Programming and Database Handout

MIS 315 - Bsharah

6

Programming Languages and Paradigms

• Programming languages are made up of keywords and grammar rules designed for creating computer instructions.– Keywords can be combined with parameters.– Low-level languages typically include commands specific

to a particular CPU or microprocessor family.– High-level languages use command words and grammar

based on human languages.

• The programming paradigm refers to a way of conceptualizing and structuring the tasks a computer performs.

Computer Programming and Database Handout

Page 7: Computer Programming and Database Handout

MIS 315 - Bsharah

7

Programming Languages

• First generation language– The lowest level programming language; composed of binary digits;

typically the only programming language understood by a CPU. – Machine language.

• Second generation language– More user friendly than first generation language; uses mnemonics for

people to use, such as ADD, SUB, MOV.– Assembly language.

• Third generation language – Requires the programmer to specify, step-by-step, exactly how the computer

must accomplish a task. Examples: C, Basic, FORTRAN.

• Fourth generation language– allows the user to specify the desired result without having to specify step-

by-step procedures. Examples: SAS, SPSS, APL.

• Fifth-generation language– Based on a declarative programming paradigm.

Lower Higher

Page 8: Computer Programming and Database Handout

MIS 315 - Bsharah

8Computer Programming and Database Handout

Programming Paradigms

• The programming paradigm refers to a way of conceptualizing and structuring the tasks a computer performs.

Page 9: Computer Programming and Database Handout

MIS 315 - Bsharah

9

Hypertext Markup Language and Extensible Markup Language• Hypertext

– An approach to data management in which data are stored in a network of nodes connected by links and are accessed through interactive browsing.

• Hyperlinks– The links that connect data nodes in hypertext.

• Hypertext document– The combination of nodes, links, and supporting indexes for any

particular topic in hypertext.

• Hypertext markup language (HTML)– The standard programming language used on the Web to create and

recognize hypertext documents.

• Extensible markup language (XML)– A programming language designed to improve the functionality of web

documents by providing more flexible and adaptable data identification.

Page 10: Computer Programming and Database Handout

MIS 315 - Bsharah

10

Comparison of HTML and XML

Page 11: Computer Programming and Database Handout

MIS 315 - Bsharah

11

Program Planning

• The problem statement defines certain elements that must be manipulated to achieve a result or goal.

• You accept assumptions as true to proceed with program planning.

• Known information helps the computer to solve a problem.

• Variables vs. constants

Computer Programming and Database Handout

Page 12: Computer Programming and Database Handout

MIS 315 - Bsharah

12Computer Programming and Database Handout

Program Planning

• Problem statement - Identify the pizza with the lowest price per square inch.

• Assuming that there are two pizzas to compare, that both pizzas contain the same toppings, and that the pizzas could be round or square, and given the prices, shapes, and sizes of the two pizzas, the computer will print a message indicating which pizza has the lower price per square inch.

Page 13: Computer Programming and Database Handout

MIS 315 - Bsharah

13Computer Programming and Database Handout

Program Coding

A text editor such as Notepad allows programmers to enter lines of code using a familiar word processing interface.

Page 14: Computer Programming and Database Handout

MIS 315 - Bsharah

14Computer Programming and Database Handout

Programming Tools

• A Software Development Kit (SDK) is a collection of language-specific programming tools that enables a programmer to develop applications for a specific computer platform.

• An Integrated Development Environment (IDE) is a type of SDK that packages a set of development tools into a sleek programming application.

• A Component is a prewritten module, typically designed to accomplish a specific task.

• An API is a set of application program or operating system functions that programmers can access from within the programs they create.

Page 15: Computer Programming and Database Handout

MIS 315 - Bsharah

15

Program Testing and Documentation

• A computer program must be tested to ensure that it works correctly.

• Program errors include– Syntax errors– Runtime errors– Logic errors

• A Debugger can help a programmer read through lines of code and solve problems.

Computer Programming and Database Handout

Page 16: Computer Programming and Database Handout

MIS 315 - Bsharah

16Computer Programming and Database Handout

Program Testing and Documentation

• Remarks or “comments” are a form of documentation that programmers insert into the program code.

Page 17: Computer Programming and Database Handout

MIS 315 - Bsharah

17

Section B: Procedural Programming

• Algorithms• Expressing an Algorithm• Sequence, Selection, and Repetition Controls• Procedural Languages and Applications

Computer Programming and Database Handout

Page 18: Computer Programming and Database Handout

MIS 315 - Bsharah

18

Algorithms

• Set of steps for carrying out a task that can be written down and implemented.

• Start by recording the steps you take to solve the problem manually.

• Specify how to manipulate information.• Specify what the algorithm should display as a

solution.

Computer Programming and Database Handout

Page 19: Computer Programming and Database Handout

MIS 315 - Bsharah

19Computer Programming and Database Handout

Algorithms

Page 20: Computer Programming and Database Handout

MIS 315 - Bsharah

20Computer Programming and Database Handout

Expressing an Algorithm

• Structured English• Pseudocode

Page 21: Computer Programming and Database Handout

MIS 315 - Bsharah

21Computer Programming and Database Handout

Expressing an Algorithm by a Flowchart

• Flowchart– The pizza program

flowchart illustrates how the computer should proceed through the instructions in the final program.

Page 22: Computer Programming and Database Handout

MIS 315 - Bsharah

22

Expressing an Algorithm - Walkthrough

• Perform a walkthrough to make sure thealgorithm works.

Computer Programming and Database Handout

Page 23: Computer Programming and Database Handout

MIS 315 - Bsharah

23Computer Programming and Database Handout

Sequence, Selection, and Repetition Controls• Subroutines,

Procedures, and Functions – sections of

code that are part of the program, but not included in the main sequential execution path.

Page 24: Computer Programming and Database Handout

MIS 315 - Bsharah

24

Sequence, Selection, and Repetition Controls• Sequence Control structure

Computer Programming and Database Handout

Executing a GOTO command directs the computer to a different part of the program.

Page 25: Computer Programming and Database Handout

MIS 315 - Bsharah

25

Sequence, Selection, and Repetition Controls• Selection Control structure

Computer Programming and Database Handout

The computer executes a decision indicated on the flowchart by the question in the diamond shape.

Page 26: Computer Programming and Database Handout

MIS 315 - Bsharah

26

Sequence, Selection, and Repetition Controls• Repetition Control structure

Computer Programming and Database Handout

To execute a loop, the computer repeats one or more commands until some condition indicates that the looping should stop.

Page 27: Computer Programming and Database Handout

MIS 315 - Bsharah

27

Procedural Languages and Applications

• Popular procedural languages include FORTRAN, COBOL, FORTH, APL, ALGOL, PL/1, Pascal, C, Ada, and BASIC.

• The procedural approach is best used for problems that can be solved by following a step-by-step algorithm.– Does not fit well with certain types of problems.

• Produces programs that run quickly and efficiently.

Computer Programming and Database Handout

Page 28: Computer Programming and Database Handout

MIS 315 - Bsharah

28

Section C: Object-Oriented Programming

• Programming language that encapsulates a small amount of data with instructions about what to do with data.– Methods: the instructions about what to do with

encapsulated data objects.– Object: the combination of a small amount of data with the

data. – Encapsulation: the process of creating an object.– Reusability feature: allows classes created for one purpose

to be used in a different object-oriented program if desired.

• Object-oriented Program Structure• Object-oriented Languages and Applications

Computer Programming and Database Handout

Page 29: Computer Programming and Database Handout

MIS 315 - Bsharah

29

Objects and Classes

• An Object represents an abstract or real-world entity.• A Class is a template for a group of objects with

similar characteristics.– A Class Attribute defines the characteristics of a set of

objects.• Public vs. private

attributes

Computer Programming and Database Handout

Page 30: Computer Programming and Database Handout

MIS 315 - Bsharah

30

Inheritance

• Passing certain characteristics from one class to other classes.– Superclass– Subclass– Class hierarchy

Computer Programming and Database Handout

Page 31: Computer Programming and Database Handout

MIS 315 - Bsharah

31

Methods and Messages

• A Method is a segment of code that defines an action.– Collect input, perform calculations, etc.– A method is activated by a message.– Can be defined along with the class they affect.

• Polymorphism refers to the ability to redefine a Method in a subclass.– Helps simplify program code.

Computer Programming and Database Handout

Page 32: Computer Programming and Database Handout

MIS 315 - Bsharah

32Computer Programming and Database Handout

Object-Oriented Program Structure

Page 33: Computer Programming and Database Handout

MIS 315 - Bsharah

33

Object-Oriented Program Structure

Computer Programming and Database Handout

Page 34: Computer Programming and Database Handout

MIS 315 - Bsharah

34

Object-Oriented Program Structure

• When the pizza program runs, on-screen prompts ask for the shape, size, and price of each pizza; then the program displays a message that indicates which pizza is the best deal.

Computer Programming and Database Handout

Page 35: Computer Programming and Database Handout

MIS 315 - Bsharah

35

Object-Oriented Languages and Applications• SIMULA was believed to be the first object-oriented

computer language.• The Dynabook project was the second major

development in object-oriented languages.• Popular object-oriented languages today are Ada95,

C++, (Visual Basic, and C#).• The OO paradigm results in decreased runtime

efficiency, but allows encapsulation, which hides the internal details of objects and their methods.

Computer Programming and Database Handout

Page 36: Computer Programming and Database Handout

MIS 315 - Bsharah

36

Section D: Declarative Programming

• The Declarative Paradigm• Prolog Facts• Prolog Rules• Input Capabilities• Declarative Languages and Applications

Computer Programming and Database Handout

Page 37: Computer Programming and Database Handout

MIS 315 - Bsharah

37Computer Programming and Database Handout

The Declarative Paradigm

• Attempts to describe a problem without specifying exactly how to arrive at a solution.– A Fact is a statement for solving a problem.– Rules describe the relationship between Facts.

• An approach to the programming process in which the programmer writes a program by specifying a set of statements and rules that define the conditions for solving the problem.

Page 38: Computer Programming and Database Handout

MIS 315 - Bsharah

38

The Declarative Paradigm

• A Decision Table is a tabular method for visualizing and specifying rules based on multiple factors.

Computer Programming and Database Handout

Page 39: Computer Programming and Database Handout

MIS 315 - Bsharah

39Computer Programming and Database Handout

Prolog Facts

Page 40: Computer Programming and Database Handout

MIS 315 - Bsharah

40

Prolog Facts

• You can query a program’s database by asking a question, called a Goal.

Computer Programming and Database Handout

The ?- prompt allows you to query a set of Prolog facts and rules.

Page 41: Computer Programming and Database Handout

MIS 315 - Bsharah

41

Prolog Facts

• Finding a value for a variable is referred to as Instantiation.

Computer Programming and Database Handout

Prolog uses a process called instantiation tosatisfy goals.

Page 42: Computer Programming and Database Handout

MIS 315 - Bsharah

42

Prolog Rules

• The order of program instructions is critically important.

Computer Programming and Database Handout

Page 43: Computer Programming and Database Handout

MIS 315 - Bsharah

43Computer Programming and Database Handout

Input Capabilities

When the pizza programruns, the pizzainfo rulecollects input for the prices, the sizes, and the shapes of two pizzas.

Page 44: Computer Programming and Database Handout

MIS 315 - Bsharah

44

Declarative Languages and Applications

• Declarative programming languages are most suitable for problems that pertain to words and concepts rather than to numbers.– Highly effective programming environment.– Not commonly used for production applications.– Minimal input and output capabilities.– Poor performance on today’s personal computer

architecture.

Computer Programming and Database Handout

Page 45: Computer Programming and Database Handout

MIS 315 - Bsharah

45Computer Programming and Database Handout

Section E: Event Driven Programming

• A Visual Development Environment (VDE) provides programmers with tools to build substantial sections of a program.– Form design grid– Control– Properties– Event– Event-

handling code

Page 46: Computer Programming and Database Handout

MIS 315 - Bsharah

46Computer Programming and Database Handout

Program Coding (Event Driven)

Controls, such as theBest Deal button, can be selected by a programmer from a properties list.

Here a programmer is selecting the background color for the Best Deal button.

Page 47: Computer Programming and Database Handout

MIS 315 - Bsharah

47Computer Programming and Database Handout

Program Coding (Event Driven)

Page 48: Computer Programming and Database Handout

MIS 315 - Bsharah

48

Section F: Secure Programming

• Black Hat Exploits• Secure Software Development• Mitigation

Computer Programming and Database Handout

Page 49: Computer Programming and Database Handout

MIS 315 - Bsharah

49

Black Hat Exploits

• Today’s operating systems, utilities, and application software are full of defects that create security holes, which are exploited by black hats.

• A buffer overflow (also called a buffer overrun) is a condition in which data in memory exceeds its expected boundaries and flows into memory areas intended for use by other data.

Computer Programming and Database Handout

Page 50: Computer Programming and Database Handout

MIS 315 - Bsharah

50Computer Programming and Database Handout

Black Hat Exploits

Page 51: Computer Programming and Database Handout

MIS 315 - Bsharah

51

Black Hat Exploits

• Verbose error messages can also present attackers with information about the directory location of programs or files, the structure of a database, or the layout of the program in memory.

Computer Programming and Database Handout

Page 52: Computer Programming and Database Handout

MIS 315 - Bsharah

52

Secure Software Development

• Most software security problems can be traced back to defects that programmers unintentionally introduce in software during design and development.

• Formal methods help programmers apply rigorous logical and mathematical models to software design, coding, testing, and verification.

• Threat modeling (risk analysis).

Computer Programming and Database Handout

Page 53: Computer Programming and Database Handout

MIS 315 - Bsharah

53Computer Programming and Database Handout

Secure Software Development

Page 54: Computer Programming and Database Handout

MIS 315 - Bsharah

54

Secure Software Development

• An attack tree is a hierarchical diagram of potential attacks against a system

Computer Programming and Database Handout

Page 55: Computer Programming and Database Handout

MIS 315 - Bsharah

55Computer Programming and Database Handout

Secure Software Development

• Defensive programming (also referred to as secure programming) is an approach to software development in which programmers anticipate what might go wrong as their programs run and take steps to smoothly handle those situations.– Source code walkthroughs– Simplification– Filtering input

Page 56: Computer Programming and Database Handout

MIS 315 - Bsharah

56Computer Programming and Database Handout

Secure Software Development

• Signed code is a software program that identifies its source and carries a digital certificate attesting to its authenticity.

Page 57: Computer Programming and Database Handout

MIS 315 - Bsharah

57

Mitigation

• Despite defensive programming and other tactics to produce secure software, some defects inevitably remain undiscovered in products that end up in the consumers’ hands.

• When bugs are discovered, the programmer’s remaining line of defense is to produce a bug fix, or patch.

Computer Programming and Database Handout

Page 58: Computer Programming and Database Handout

MIS 315 - Bsharah

58

Mitigation

• Take the following steps to avoid security problems that stem from software defects.– Select applications from software publishers with a good

security track record.– Watch for patches and apply them.– Consider using open source software, which has been

extensively reviewed by the programming community.– Keep your firewall and antivirus software deployed and up-

to-date.

Computer Programming and Database Handout

Page 59: Computer Programming and Database Handout

MIS 315 - Bsharah

5959

Section G: Structured Query Language (SQL)• SQL is the language for querying and updating

databases.• “universal” database language• Developed in the mid-1970’s by IBM• Original name SEQUEL changed to SQL in 1980.

Page 60: Computer Programming and Database Handout

MIS 315 - Bsharah

60

Plan Ahead for a Query

• Select the fields for the query• Determine which table or tables contain these fields• Determine criteria• Determine sort order• Determine grouping• Determine any update operations to be performed

60

Page 61: Computer Programming and Database Handout

MIS 315 - Bsharah

61

Creating a New SQL Query in Access2007 • Hide the Navigation Pane• Click Create on the Ribbon to display the Create tab• Click the Query Design button on the Create tab to

create a query• Close the Show Table dialog box without adding any

tables• Click the View button arrow to display the View menu• Click SQL View to view the query in SQL view

61