introduction to computer programming ics3u/4u · what is a programming language? a high-level...

18
An Introduction to Java (ICS4U) & An Introduction to Turing (ICS3U)

Upload: others

Post on 30-May-2020

22 views

Category:

Documents


1 download

TRANSCRIPT

An Introduction to Java (ICS4U)

& An Introduction to Turing (ICS3U)

What is a Programming Language? A high-level language is a programming language that

enables a programmer to write programs that are more or less independent of a particular type of computer.

Such languages are considered high-level because they are closer to human languages and further from machine languages.

high-level languages you might have heard of are Turing, Python, C or C++, Java and Perl.

programs written in a high-level language have to be translated before they can run which is a small disadvantage of high-level languages.

Low-level languages, are sometimes called machine language or assembly language.

Low-level programs can only run on one kind of computer, and have to be rewritten to run on another.

high-level languages are portable, meaning that they can run on different kinds of computers with few or no modifications.

almost all programs are written in high-level languages.

What is a Programming Language?(continued)

There are two ways to translate a program: interpreting and compiling.

An interpreter is a program that reads a high-level program and does what it says, translating the program line-by-line, alternately reading lines and carrying out commands.

A compiler is a program that reads a high-level program and translates it all at once, before running any of the commands.

What is a Programming Language?(continued)

The compiler translates source code into a language the computer can understand, machine language (the computer understands binary language which are 0’s and 1’s)

How it works:

1) Source code is compiled into object code

2) Object code is combined with library files by a

linker

3) Produces the file that can be executed by the

computer (executable file)

What is a Programming Language?(continued)

Note: Library files are object codes already compiled that provide operations that many computers use repeatedly.

What is a Programming Language?(continued)

Java is both compiled and interpreted, instead of translating programs into machine language, the Java compiler generates byte code.

Byte code is easy (and fast) to interpret, like machine language but it is also portable, like a high-level language possible to compile a program on one machine, transfer the byte code to another machine, and then interpret the byte code on the other machine.

What is a Programming Language?(continued)

What is a Programming Language?(continued)

What is a Programming Language?(continued) structured programming is the idea that within a program

there are groups of statements that are used to control the flow of information.

These groups of statements are called control constructs which consists of:

1) linear sequence: where statements are executed one

after the other in the order in which they are written.

2) repetition: where a group of statements is to be

executed repeatedly.

3) selection: where one group of statements is selected for

execution from a number of alternatives.

Structured programming refers to a systematic way of analyzing computer problems and designing solutions called top-down programming.

In top-down programming, a problem is broken down into a series of smaller problems, each of which is then solved.

Once the smaller problems are solved, the solutions are combined to solve the larger problem.

What is a Programming Language?(continued)

What is a Programming Language?(continued)

Object-oriented programming is a way of designing and writing programs based on the concept that a program can be created as a collection of objectswhich work together.

Each of these objects is a set of data and methods that operate on this set of data.

The details of how the data is stored and how the methods work are hidden from the user.

What is a Programming Language?(continued)

An object is created from a class from which many such objects can be created.

One class can inherit (or borrow) features from another class.

Classes which perform specific tasks can also be reused in other programs, thus speeding up program development.

Some object-oriented programming languages include C++ (developed by Bjarne Stroustrup), Java (developed by James Gosling), and Object Oriented Turing (developed by Ric Holt).

What is a Programming Language?(continued)

What is a program The instructions look different in different programming languages,

but there are a few basic operations most languages perform:

1) input: Get data from the keyboard, or a file, or some other

device.

2) output: Display data on the screen or send data to a file or

other device.

3) math: Perform basic mathematical operations like addition and

multiplication.

4) testing: Check for certain conditions and run the appropriate

sequence of statements.

5) repetition: Perform some action repeatedly, usually with

some variation.

Debugging programming errors are called bugs and the process

of tracking them down and correcting them is called debugging.

There are a three kinds of errors that can occur in a program:

1) Syntax Errors

2) Run-time Errors

3) Logic Errors

Syntax Errors Syntax refers to the structure of your program and the

rules about that structure.

In English, a sentence must begin with a capital letter and end with a period.

Compilers are not forgiving.

If there is a single syntax error anywhere in your program, the compiler will print an error message and quit, and you will not be able to run your program.

The syntax rules are different for various programming languages.

Run-time Errors In Java, run-time errors occur when the interpreter is

running the byte code and something goes wrong.

Java and Turing tend to be a safe languages, which means that the compiler catches a lot of errors.

So run-time errors are rare, especially for simple programs.

Logic Errors If there is a logic error in your program, it will

compile and run without generating error messages, but it will not do the right thing.

Specifically, it will do what you told it to do.

Identifying logic errors can be tricky because you have to work backwards, looking at the output of the program and trying to figure out what it is doing.