seit.unsw.adfa.edu.au

Download Report

Transcript seit.unsw.adfa.edu.au

Computer Tools:
Programming Languages
Lecture 20: Supporting Material
Dr Kathryn Merrick
Tuesday May 26th, 2009
Overview
 Why have different
programming languages?
 What are the main
differences between
different languages?
 Tips for transferring your
problem solving skills to
other programming
languages
Machine Language
00000010101010111111111000110100101001010
10100101010010101000000001010100101011111
11111001010100100001010101010101001011010
10010101010101010101100000010101010111111
11100011010010100101010100101010010101000
00000101010010101111111111001010100100001
01010101010100101101010010101010101010101
10000001010101011111111100011010010100101
01010010101001010100000000101010010101111
11111100101010010000101010101010100101101
01001010101010101010111001000111111100000
Assembly Language
High Level Languages
Some Differences Between High
Level Languages
Matlab
Java
Interpreted
Compiled
Procedural
Object-Oriented
Weakly Typed
Strongly Typed
Interpreted Languages
 Interpreter converts each line of source code to
machine code while the program is running.
Matlab
source
code
Convert line of
source code to
machine code and
run it
Interpreter
(.m file)
Get a line of
source code
Compiled Languages
 Entire program is converted to machine code at
once. Then the machine code is run.
Java byte
code
Java
source
code
(.java file)
(.class file)
Run the
program
Weakly Typed Languages
 Variables are not given a type at design time:
age = 54
name = ‘John’
 Variables may change their type at run time:
age = ‘fifty-four’
Strongly Typed Languages
 Variables are given a type at design time and must
keep the same type for the life of the program:
int age = 54;
String name = “John”;
Procedural Languages
 Functions permit encapsulation
of logical units of the program
% Function to compute the sum of
% squares of input elements
function result = sum_squares(inputs)
result = 0;
for counter = 1:length(inputs)
result = result + inputs(counter)^2;
end
end
Object-Oriented Languages
 Two main levels of encapsulation:
 Functions/Methods
 Classes/Objects
 Classes permit related functions to be grouped together and
accessed in a logical way
// Class with methods for maths operations
public class MyMathsOperations
{
// Method to compute the sum of squares of inputs
public double sumSqr(double[] inputs)
{
double result = 0;
for (int counter=0; counter<inputs.length;
counter++)
{
result = result +
inputs(counter)*inputs(counter);
}
return result;
Activity 1:
O-O Design
Summary
 After this lecture you should be
able to define:






Procedural
Object-oriented
Weakly typed
Strongly typed
Interpreted
Compiled
 And have an awareness of
different programming languages
and their purposes