computer programming a program is a set of instructions a computer follows in order to perform a...

18
Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions form an algorithm

Upload: rodger-norton

Post on 12-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

Computer Programming A program is a set of instructions a computer

follows in order to perform a task. solve a problem

Collectively, these instructions form an algorithm

Page 2: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

Why Program?

Computers are tools that can be programmed to perform many functions.

Computers are versatile because they can be programmed.

Implement ______________________ to solve problems or calculate answers to problems, listen to music …

Page 3: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

Why Program?

Computers are tools that can be programmed to perform many functions.

Computers are versatile because they can be programmed.

Implement algorithms to solve problems or calculate answers to problems, listen to music …

Page 4: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

What to Program?Aspects of a computer program that must be designed:

The logical flow of the instructions The mathematical procedures The layout of the programming statements The appearance of the screens The way information is presented to the user The program’s “user friendliness”

Page 5: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

How to Program?

Programs must be analytically correct. Programs rarely work the first time they are

programmed. Programmers must perform the following on a

continual basis: analyze, experiment, correct, and redesign.

Programming languages have strict rules, known as syntax, that must be carefully followed.

Page 6: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

Programming Languages

In order to understand a program, the computer needs the program to be written in machine language. Machine language is written using binary numbers. The binary numbering system (base 2) only has two

digits (0 and 1). Example machine language computer code:

00101010101010101110010101010101010101010101010111101010000101010110

Problem? Machine language for a Mac CPU is not the same as

the machine language as an Intel CPU. Different processors have different machine

languages

Page 7: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

Programming Languages In the distant past, programmers wrote programs

in machine language. Programmers developed higher level

programming languages to make things easier. Some common programming languages:

BASIC COBOL Pascal C C++ Java

Page 8: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

A Bit On Java First Developed by Sun Microsystems in 1991 There was a need for a programming language

that would run on various devices. Ideal for internet browsers

Java incorporated into Netscape in 1995 Java is “cross platform”, meaning that it can run

on various computer operating systems.

Page 9: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

How does Java work?

A programmer writes Java programming statements for a program. These statements are known as source code. A text editor is used to edit and save a Java

source code file. (We will use Jcreator) Source code files have a .java file extension. A ___________ is a program that translates

source code into an executable form.

Page 10: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

How does Java work?

A programmer writes Java programming statements for a program. These statements are known as source code. A text editor is used to edit and save a Java

source code file. (We will use Jcreator) Source code files have a .java file extension. A compiler is a program that translates

source code into an executable form.

Page 11: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

The Compiler and the Java Virtual Machine

A compiler is run using a source code file as input.

Syntax errors are mistakes that the programmer has made that violate the rules of the programming language. Discovered at “compile time”

The compiler creates another file that holds the translated instructions.

Page 12: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

The Compiler and the Java Virtual Machine

The Java compiler translates a Java source file into a file that contains byte code instructions. Files end with at .class extension

Byte code instructions are the machine language of the Java Virtual Machine (JVM) and cannot be directly executed directly by the CPU.

Page 13: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

Program Development Process

Text editor Source code(.java)

Saves Java statements

Java compiler

Is read by

Byte code(.class)

Produces

JavaVirtual

Machine

Is interpreted by

ProgramExecution

Results in

Page 14: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

Portability

A program is ___________________________ if it may be written on one type of computer and then run on a wide variety of computers, with little or no modification.

Java byte code runs on the JVM and not on any particular CPU; therefore, compiled Java programs are highly portable.

JVMs exist on many platforms:

•Windows•Mac•Linux

Page 15: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

Portability

A program is __portable________________ if it may be written on one type of computer and then run on a wide variety of computers, with little or no modification.

Java byte code runs on the JVM and not on any particular CPU; therefore, compiled Java programs are highly portable.

JVMs exist on many platforms:

•Windows•Mac•Linux

Page 16: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

Portability With most programming languages,

portability is achieved by compiling a program for each CPU it will run on.

Java provides an JVM for each platform so that programmers do not have to recompile for different platforms.

Page 17: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

Portability

Java VirtualMachine for Windows

Byte code(.class)

Java VirtualMachine for Linux

Java VirtualMachine for Mac

Java VirtualMachine for Unix

Page 18: Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions

How To Program (Our way) 1. Understand the problem 2. Visualize 3. Write down the algorithm on paper

Informal high-level description of an algorithm Step1: … Step2: …

4. Translate to Java 5. Save and Compile 6. If does not compile then fix error, save and compile. 7. Run 8. Test code to make sure it works for all expected input