Lecture 5
Lecture 5
Lecture 5
561
Information Technology Essentials
Session 5
Programming Languages
Acknowledgments:
Copyright © 2005 Thomas Malone, Stuart Madnick Slides marked “SM” are adapted from Stuart Madnick, MIT.
Outline
• Types of software
• Examples
– Java
– Y2K
Types of software
• System software
– Operating systems
– Programming languages
– Database systems
• Application software
– General office tasks (word processing, etc.)
– Accounting
– Design
– Factory automation
– …
Programming languages
• Machine language
• Assembly language
• High-level languages
• Fourth-generation languages
A sample LMC program
• Binary
• Machine dependent
• Example:
01110110001010010010 ….
Assembly language
• Mnemonic
• Symbolic addressing
• Example:
Get X
Add Y
Store Z
Automatically translating assembly
language to machine language
Get X 11001000100
Add Y 01100100011
Store Z Assembler 10001011001
... ...
Assembly Machine
language language
program program
(“source code”) (“object code”)
High-level languages
• General purpose
• Example:
Z=X+Y
High-level languages - Examples
• Fortran
• Basic
• Visual Basic
•C
• C++
• Java
Example 1 – Basic
! L QF L OQF X L G O F X H OX R V W L R OX R OU D P V H
K G
QF X O �X R Q G O V L I O Y Q OJ QF H OX R O L OV J OQF X L G OD V W O F X E
QF X O �X R V W L R O X R O U D P V H OX D O? ? ? OX V OQF H QK X OX R O F H OV J OH X E
QF X
G W I Z
K V W F X OZ
QF X O� G O F X O OF W I P E
QF W X OF W I P
H V OY R Q O F W I P O ` O ? ? ?
G W I Z G W I � F W I P
K V W F X Z K V W F X � 6
QF X O� G O F X OX R OF ' X OF W I P E
QF W X OF W I P
V V
L Z G W I +K V W F X
Q F X O �X R O L O V J O X R O F W I P O Q G E2O L
F H
Example 2 – C++
++O L QF L OQF X L G O F X H OX R V W L R OX R OU D P V H
( 5 *$ 9 / � � O ` 5 0 : ) 8 � . < ,
< . 5 *O 1 O
3O
90 . )O. � 8 . ; � 2
5 *) */ < � 8 � O $ 0 / *) � 8 O Z O 2O O 5 *) : / < O Z O 2
$ 0 / ) ` ` O �X R Q G O V L I O Y Q O J Q F H O X R O L O V J O Q F X L G O D V W O F X O *E2
$ 0 / ) ` ` O �X R V W L R O X R O U D P V H O X D O ? ? ? O X V O Q F H Q K X O F H O V J O H X O *E2
$ 0 / ) ` ` O� G O F X O OF W I P E2
$ 5 * O */ < � 8 2
, 5 9 � O 1 */ < � 8 O % Z ? ? ?
3
: / < O Z : / < O � O */ < � 8 2
$ 0 / *) � 8 � � 2
$ 0 / ) ` ` O �* G F X O X R O F ' X O F W I P E2
$ 5* */ < � 8 2
&
. � 8 . ; � O Z O : / < O + O $ 0 / *) � 8 2
$ 0 / ) ` ` O �*X R L O V J O X R O F W I P G O Q G O �` ` O . � 8 . ; � 2
&
Example 3 – Java
{
import java.io.*; BufferedReader in = new BufferedReader(new
import java.lang.*; InputStreamReader(System.in));
/** String cin = "0";
** Prompts user for list of numbers and outputs average System.out.println("Please enter a number.");
**/ while (!(cin=in.readLine()).equals("999"))
{
class AverageNumbers { sum = sum + Integer.parseInt(cin);
public static void main (String[] args) { counter = counter + 1;
float sum = 0; System.out.println("Please enter another
float average = 0; number.");
int counter = 0; }
in.close();
System.out.println("THIS PROGRAM WILL FIND THE average = sum/counter;
AVERAGE OF THE INTEGERS YOU ENTER System.out.println("The average of the numbers is :
THROUGH THE KEYBOARD. TYPE 999 TO "+average);
INDICATE END OF DATA."); }
catch (IOException e)
try {
System.out.println("Ooops..");
}
}
}
Automatically translating high-level
language to machine language
Z=X+Y 11001000100
... 01100100011
Compiler 10001011001
...
High-level Machine
language language
program program
(“source code”) (“object code”)
“Interpreting” high level languages
Z=X+Y
...
Interpreter
High-level
language
program
(“source code”)
Interpreting high level languages
• Advantages
– Can give machine independence
» (e.g., one machine can “look” like another)
– Can be easier to debug and modify
– Can give more flexibility at “run time”
• Disadvantages
– Slower
“Fourth-generation” languages
• Special purpose
• Examples:
– Scripting languages
» FIND ALL RECORDS WHERE NAME IS “SMITH”
– Spreadsheet formulas?
Object-oriented programming
S
D
Internet
J
Sun/UNIX
HTML
page
Java
applet
HTML
page
Java
applet } same
}
Interpreter interpreter Interpreter interpreter
Client environments SM
Java reality check